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.

Built from https://develop.svn.wordpress.org/trunk@58206


git-svn-id: http://core.svn.wordpress.org/trunk@57669 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Tammie Lister 2024-05-27 12:28:18 +00:00
parent 31b37a5eb3
commit b4aa9d18b1
3 changed files with 15 additions and 7 deletions

View File

@ -689,6 +689,19 @@ if ( ! function_exists( 'wp_get_list_item_separator' ) ) :
} }
endif; endif;
/**
* If a regular post or page, and not the front page, show the featured image below the header.
* Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
*
* @since Twenty Seventeen 3.7
*
* @return bool Whether the post thumbnail should be shown.
*/
function twentyseventeen_should_show_featured_image() {
$show_featured_image = ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() );
return apply_filters( 'twentyseventeen_should_show_featured_image', $show_featured_image );
}
/** /**
* Implement the Custom Header feature. * Implement the Custom Header feature.
*/ */

View File

@ -47,12 +47,7 @@
</header><!-- #masthead --> </header><!-- #masthead -->
<?php <?php
if ( twentyseventeen_should_show_featured_image() ) :
/*
* If a regular post or page, and not the front page, show the featured image.
* Using get_queried_object_id() here since the $post global may not be set before a call to the_post().
*/
if ( ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) && has_post_thumbnail( get_queried_object_id() ) ) :
echo '<div class="single-featured-image-header">'; echo '<div class="single-featured-image-header">';
echo get_the_post_thumbnail( get_queried_object_id(), 'twentyseventeen-featured-image' ); echo get_the_post_thumbnail( get_queried_object_id(), 'twentyseventeen-featured-image' );
echo '</div><!-- .single-featured-image-header -->'; echo '</div><!-- .single-featured-image-header -->';

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.6-alpha-58205'; $wp_version = '6.6-alpha-58206';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.