I am using a static page for my frontpage, and another page for my blog index.

However, I've noticed that if I use the same code from my page.php file for displaying the featured image (which works fine), it will not show the featured image for the page designed as my blog index page. Why is this?

This is the snippet of code from page.php, from the top of the file:

<?php get_header(); ?>
<?php if ( has_post_thumbnail() ) {
    echo 'Featured image here';
} ?>

But this code will not produce the echoed result when placed in index.php

  • Blog index is a page of blog posts, right? How are you setting featured image? What is the filename of the blog index? Are you using page template? – bravokeyl Aug 22 '16 at 10:17
  • Correct, I have a page that is set to be the blog index (in Settings > Reading). The filename of the blog index is index.php – Lee Aug 22 '16 at 10:18
  • Since it's index.php it does not work, has _post_thumbnail is to be used in the loop. – bravokeyl Aug 22 '16 at 10:22
  • wp_get_attachement functions for your purpose. – bravokeyl Aug 22 '16 at 10:23
  • Please expand on that, because that's not a valid function. Do you mean wp_get_attachment_url? As this returns false too. – Lee Aug 22 '16 at 10:25

Managed to find an alternative function that correctly calls the featured image set for the Blog index page by using this:

<?php get_header(); ?>
<?php if ( is_home() && get_option('page_for_posts') ) {
    echo get_the_post_thumbnail_url( get_option('page_for_posts') );
} ?>

Thanks to those for your help

  • Thanks for sharing the answer, please don't forget to accept this as an answer after two days. – bravokeyl Aug 22 '16 at 10:49
  • Hi! You can accept this as the answer so that it won't come up in unanswered questions list. – bravokeyl Aug 25 '16 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.