Using WordPress ‘feed_links_extra_show_post_comments_feed’ PHP filter

The feed_links_extra_show_post_comments_feed WordPress PHP filter enables you to control the display of post comments feed link on a per-post basis, independently of the feed_links_show_comments_feed filter.

Usage

add_filter( 'feed_links_extra_show_post_comments_feed', 'your_function_name', 10, 1 );
function your_function_name( $show_comments_feed ) {
    // Your custom code here
    return $show_comments_feed;
}

Parameters

  • $show_comments_feed (bool): Whether to display the post comments feed link. Defaults to the feed_links_show_comments_feed filter result.

More information

See WordPress Developer Resources: feed_links_extra_show_post_comments_feed

Examples

Disable post comments feed link for all posts

Hide post comments feed link for all posts on your website.

add_filter( 'feed_links_extra_show_post_comments_feed', 'disable_post_comments_feed_link' );
function disable_post_comments_feed_link( $show_comments_feed ) {
    return false;
}

Enable post comments feed link for specific post ID

Show post comments feed link only for the post with the given ID.

add_filter( 'feed_links_extra_show_post_comments_feed', 'enable_post_comments_feed_link_for_specific_post', 10, 1 );
function enable_post_comments_feed_link_for_specific_post( $show_comments_feed ) {
    if ( is_single( 123 ) ) {
        return true;
    }
    return false;
}

Disable post comments feed link for specific category

Hide post comments feed link for posts in a specific category.

add_filter( 'feed_links_extra_show_post_comments_feed', 'disable_post_comments_feed_link_for_category' );
function disable_post_comments_feed_link_for_category( $show_comments_feed ) {
    if ( in_category( 'news' ) ) {
        return false;
    }
    return $show_comments_feed;
}

Enable post comments feed link for specific post format

Show post comments feed link only for posts with the ‘gallery’ post format.

add_filter( 'feed_links_extra_show_post_comments_feed', 'enable_post_comments_feed_link_for_gallery_post_format' );
function enable_post_comments_feed_link_for_gallery_post_format( $show_comments_feed ) {
    if ( has_post_format( 'gallery' ) ) {
        return true;
    }
    return false;
}

Enable post comments feed link for logged-in users

Show post comments feed link only for logged-in users.

add_filter( 'feed_links_extra_show_post_comments_feed', 'enable_post_comments_feed_link_for_logged_in_users' );
function enable_post_comments_feed_link_for_logged_in_users( $show_comments_feed ) {
    if ( is_user_logged_in() ) {
        return true;
    }
    return false;
}