Make WordPress Core

Changeset 39624


Ignore:
Timestamp:
12/20/2016 10:59:28 PM (8 years ago)
Author:
davidakennedy
Message:

Twenty Seventeen: Hardens the logic for calling featured image in header.php

This change uses get_queried_object_id() here since the $post global may not be set before a call to the_post().

Props westonruter.

Fixes #39302.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyseventeen/header.php

    r38985 r39624  
    4242
    4343    <?php
    44     // If a regular post or page, and not the front page, show the featured image.
    45     if ( has_post_thumbnail() && ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) ) :
     44
     45    /*
     46     * If a regular post or page, and not the front page, show the featured image.
     47     * Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
     48     */
     49    if ( ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() ) ) :
    4650        echo '<div class="single-featured-image-header">';
    47         the_post_thumbnail( 'twentyseventeen-featured-image' );
     51        echo get_the_post_thumbnail( get_queried_object_id(), 'twentyseventeen-featured-image' );
    4852        echo '</div><!-- .single-featured-image-header -->';
    4953    endif;
Note: See TracChangeset for help on using the changeset viewer.