'Wordpress blog page featured image
I like to use the page's featured images in a background image in the header. When I add a new page and set the featured image, it appears as background image works exactly what I wanted. But on a Blog main page (the Home, page of displaying posts) I set the featured image and in the header display the first post's featured image insetad the one I set at the page's featured image. Tried to find solution, but nothing works, don't know how to magae it. Here is my code that handle background image:
<div class="sub-header"
<?php
if (has_post_thumbnail( $post->ID ) ):
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
echo 'style="background-image: url(\'';
echo $image[0];
echo '\');"';
endif;
?>
>
</div>
Solution 1:[1]
Make the custom image source, whether it's assigned in the customizer or hard coded.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Braiam |