0

So I have a static page for the news page in wordpress, and its featured image as a breadcrumb image. I query it with this: <?php the_post_thumbnail_url(get_option('page_for_posts')); ?>. The problem is this function for whatever reason outputs the featured image of the first post instead of the featured image for the posts page.

My entire home.php looks like this (with irrelevant html code cut out)

<?php get_header(); ?>

<?php the_post_thumbnail_url(get_option('page_for_posts')); ?>

<?php
  if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

<!-- code for the posts -->

<?php
  endwhile; endif;
?>

<?php get_footer(); ?>
3
  • are you using a static front page? do you have a 'page for posts' set?
    – Michael
    Commented Sep 15, 2017 at 0:59
  • ps: consider to use 'page_on_front' codex.wordpress.org/Option_Reference
    – Michael
    Commented Sep 15, 2017 at 1:07
  • Yes, I have both static front page which is handled by front_page.php, and a page for posts set (handled by home.php). The issue occurs on the posts page.
    – Fiodor
    Commented Sep 15, 2017 at 1:56

1 Answer 1

3

the_post_thumnbail() doesn't accept an arbitrary post id as an argument. It just takes a size to display. To get the post thumbnail URL of a given post, you need to use get_the_post_thimbnail_url():

<?php echo get_the_post_thumbnail_url( get_option( 'page_for_posts' ), 'full' ); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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