Feeds: Remove comment feed HTML headers when empty.

Remove the `link[rel=alternate]` element from the HTML header when the comment feeds are disabled. Previously the HTML element was output with an empty `href` attribute.

The element is removed if `get_post_comments_feed_link()` returns an empty string or the feed is disabled via the `feed_links_show_comments_feed` filter.

Props barryceelen, audrasjb, costdev, rachelbaker, Boniu91.
Fixes #54703.


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


git-svn-id: http://core.svn.wordpress.org/trunk@52714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2022-04-11 05:03:03 +00:00
parent cf4f9c9e61
commit b90d225de1
2 changed files with 11 additions and 4 deletions

View File

@ -3153,9 +3153,16 @@ function feed_links_extra( $args = array() ) {
$id = 0;
$post = get_post( $id );
if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
$title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
$href = get_post_comments_feed_link( $post->ID );
/** This filter is documented in wp-includes/general-template.php */
$show_comments_feed = apply_filters( 'feed_links_show_comments_feed', true );
if ( $show_comments_feed && ( comments_open() || pings_open() || $post->comment_count > 0 ) ) {
$title = sprintf( $args['singletitle'], get_bloginfo( 'name' ), $args['separator'], the_title_attribute( array( 'echo' => false ) ) );
$feed_link = get_post_comments_feed_link( $post->ID );
if ( $feed_link ) {
$href = $feed_link;
}
}
} elseif ( is_post_type_archive() ) {
$post_type = get_query_var( 'post_type' );

View File

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