When you have the Posts Page:
set to “Blog” and then you visit the page directly (via the slug) does the header image display?
Setting the static “Posts” page to your “Blog” page overrides the template. WordPress will use the Template Hierarchy to figure out which file to use to display the blog posts.
The problem is that WP_Query contains the list of posts to display because the settings are telling it that that page is used to display posts, and not that it is an individual page.
This means the template won’t necessarily be aware of the page settings from when you edited the page.
We need to look at conditional tags documentation to find the right pattern to use:
if ( is_front_page() && is_home() ) {
// Default homepage
} elseif ( is_front_page() ) {
// static homepage
} elseif ( is_home() ) {
// blog page
} else {
//everything else
}
Using that pattern (or something similar) you can update your code to this:
// Use Conditional Tags to find out if you are on the header page
<?php if ( is_home() ) : ?>
<img src="https://wordpress.stackexchange.com/questions/251599/<?php echo get_the_post_thumbnail_url(*BLOG PAGE ID HERE*,"full'); ?>" alt="header" />
<?php else : ?>
<img src="<?php echo get_the_post_thumbnail_url('full'); ?>" alt="header" />
<?php endif; ?>
Using something like that, WP will grab the thumbnail URL based on the page settings.
Note my usage of get_the_post_thumbnail_url()
including the Page ID to pull the header image from. Also your usage of the_post_thumbnail_url()
is incorrect. The echo
you used is redundant since the_post_thumbnail_url()
is used to print the thumbnail URL. See the source here.
EDITED for clarity