So for all of the other pages on my wordpress site I am able to display the featured image for the page. However, on the page that all of my posts are displayed the featured image does not display even if it is set.
Here is the code I am using to display the featured image on all other pages.
<?php if ( has_post_thumbnail() ): {
$src = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
}?>
<div class="featured-image-full-width" style="background-image: url( <?php echo $src; ?> ) !important; height: 400px; background-size: cover; background-repeat: no-repeat; background-position: center;"></div>
<?php endif; ?>
This does not work on the page that is chosen to display posts though. Keep in mind that I need to display the featured image as a background image so that it is full width of the page and not stretched. (IE and Edge don't support "object-position" so this is my way of working around that)
Let me know if anything is not clear.
After spending the past two hours researching and trying different things I was able to figure out a solution.
<?php if(is_home()) {
$img = wp_get_attachment_image_src(get_post_thumbnail_id(get_option('page_for_posts')),'full');
$featured_image = $img[0];
}?>
<div class="featured-image-full-width" style="background-image: url( <?php echo $featured_image ?> ) !important; height: 400px; background-size: cover; background-repeat: no-repeat; background-position: center"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With