Retrieve the custom background image for the current active theme.
<?php get_background_image(); ?>
None.
This example could be used to detect whether the current Page/Post has a Featured Image set – if so, it will use the Featured Image as the page background, if not it will use the current active theme's default background image. As is, this should be used in the <head> of the page template, just after the call to wp_head():
<?php
// declare $post global if used outside of the loop
global $post;
// check to see if the theme supports Featured Images, and one is set
if (current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID )) {
// specify desired image size in place of 'full'
$page_bg_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$page_bg_image_url = $page_bg_image[0]; // this returns just the URL of the image
} else {
// the fallback – our current active theme's default bg image
$page_bg_image_url = get_background_image();
}
// And below, spit out the <style> tag... ?>
<style type="text/css" id="custom-background-css-override">
body.custom-background { background-image: url('<?php echo $page_bg_image_url; ?>'); }
</style>
Since: 3.0.0
get_background_image() is located in wp-includes/theme.php.
background_image(), background_color(), get_background_color()