Home › Forums › Support › Featured image on single post as div background. › Reply To: Featured image on single post as div background.
June 11, 2016 at 7:35 am
#201063
Nick
Thank you Tom, that did the trick.
At first the code snippet you provided didn’t exactly work. With the help of the link you provided, I was able to get it working.
I replaced
background-image: url( $thumb );
with
background-image: url('<?php echo $thumb['0'];?>')
and it worked perfectly.
I also added the following CSS so that the post image is hidden on the single page.
img.wp-post-image {
display: none;
}
Ultimately, my final code snippet looks like this:
<?php
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
if ( $thumb && is_single() ) {
?>
<style type="text/css">
div.page-header-image-single {
background-image: url('<?php echo $thumb['0'];?> ');
background-attachment: fixed;
background-repeat: no-repeat;
background-position: top;
width: 100%;
height: 300px;
margin: 0px;
}
img.wp-post-image {
display: none;
}
</style>
<?php
}
?>
Thank you again for your help. The add-on made it very easy.