WordPress.org

Forums

Featured image custom background image (1 post)

  1. Dan Stramer
    Member
    Posted 3 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic