WordPress.org

Support

Support » How-To and Troubleshooting » Featured image custom background image

Featured image custom background image

  • Hi,
    I am using a featured image for the page’s background image in my website.
    It works fine, the problem is that when I don’t pick a featured image I would like it to roll back to a default image. I am having trouble with this part.
    This is the code I have:

    <?php global $post; ?>
    <?php
    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),  false, '' );
    ?>
    
    <body <?php body_class(); ?>
    		<?php if($src !== '') { echo 'style="background:url( '. $src[0] . ' ) no-repeat center top;" ';
    		 } else { echo 'style="background:url(images/default-bg.png) repeat-x;"'; } ?> >

    Thanks in advance to any help,
    Dan

  • The topic ‘Featured image custom background image’ is closed to new replies.
Skip to toolbar