Make WordPress Core

Changeset 58206


Ignore:
Timestamp:
05/27/2024 12:26:51 PM (2 months ago)
Author:
karmatosed
Message:

Twenty Seventeen: Add filter for display of featured image in header.

When a layout doesn't use custom post types it was appearing broken. This adds a filter for the display of the featured image to resolve this.

Props justnorris, JPry, davidakennedy, SergeyBiryukov, zkarj, poena, nhrrob, lamarajan.
Fixes #39281.

Location:
trunk/src/wp-content/themes/twentyseventeen
Files:
2 edited

Legend:

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

    r58135 r58206  
    691691
    692692/**
     693 * If a regular post or page, and not the front page, show the featured image below the header.
     694 * Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
     695 *
     696 * @since Twenty Seventeen 3.7
     697 *
     698 * @return bool Whether the post thumbnail should be shown.
     699 */
     700function twentyseventeen_should_show_featured_image() {
     701    $show_featured_image = ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() );
     702    return apply_filters( 'twentyseventeen_should_show_featured_image', $show_featured_image );
     703}
     704
     705/**
    693706 * Implement the Custom Header feature.
    694707 */
  • trunk/src/wp-content/themes/twentyseventeen/header.php

    r55276 r58206  
    4848
    4949    <?php
    50 
    51     /*
    52      * If a regular post or page, and not the front page, show the featured image.
    53      * Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
    54      */
    55     if ( ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() ) ) :
     50    if ( twentyseventeen_should_show_featured_image() ) :
    5651        echo '<div class="single-featured-image-header">';
    5752        echo get_the_post_thumbnail( get_queried_object_id(), 'twentyseventeen-featured-image' );
Note: See TracChangeset for help on using the changeset viewer.