Using WordPress ‘feed_links_show_comments_feed’ PHP filter

The feed_links_show_comments_feed WordPress PHP filter allows you to control the visibility of the comments feed link on your website.

Usage

add_filter('feed_links_show_comments_feed', 'your_custom_function');
function your_custom_function($show) {
  // your custom code here
  return $show;
}

Parameters

  • $show (bool): Whether to display the comments feed link. Default is true.

More information

See WordPress Developer Resources: feed_links_show_comments_feed

Examples

To hide the comments feed link on your website, set the $show parameter to false.

add_filter('feed_links_show_comments_feed', 'hide_comments_feed_link');
function hide_comments_feed_link($show) {
  return false;
}

Show comments feed link only on single post pages

To display the comments feed link only on single post pages, check if is_single() is true.

add_filter('feed_links_show_comments_feed', 'show_comments_feed_on_single');
function show_comments_feed_on_single($show) {
  if (is_single()) {
    return true;
  }
  return false;
}

To display the comments feed link only to logged-in users, check if is_user_logged_in() is true.

add_filter('feed_links_show_comments_feed', 'show_comments_feed_to_logged_in_users');
function show_comments_feed_to_logged_in_users($show) {
  if (is_user_logged_in()) {
    return true;
  }
  return false;
}

In this example, we’ll display the comments feed link only if a specific custom field (show_comments_feed) is set to true.

add_filter('feed_links_show_comments_feed', 'show_comments_feed_based_on_custom_field');
function show_comments_feed_based_on_custom_field($show) {
  global $post;
  $show_feed = get_post_meta($post->ID, 'show_comments_feed', true);
  if ($show_feed == 'true') {
    return true;
  }
  return false;
}

Show comments feed link only on specific post types

Display the comments feed link only on specific post types, such as ‘post’ and ‘portfolio’.

add_filter('feed_links_show_comments_feed', 'show_comments_feed_on_specific_post_types');
function show_comments_feed_on_specific_post_types($show) {
  $allowed_post_types = array('post', 'portfolio');
  if (in_array(get_post_type(), $allowed_post_types)) {
    return true;
  }
  return false;
}