The feed_links_show_posts_feed WordPress PHP filter allows you to control the display of the posts feed link on your website.
Usage
add_filter('feed_links_show_posts_feed', 'your_custom_function');
function your_custom_function($show) {
// your custom code here
return $show;
}
Parameters
- $show (bool): Whether to display the posts feed link. Default is true.
More information
See WordPress Developer Resources: feed_links_show_posts_feed
Examples
Disable posts feed link
To completely disable the posts feed link, set the $show variable to false.
add_filter('feed_links_show_posts_feed', 'disable_posts_feed_link');
function disable_posts_feed_link($show) {
$show = false;
return $show;
}
Display posts feed link for logged-in users only
To show the posts feed link only to logged-in users, check if the user is logged in.
add_filter('feed_links_show_posts_feed', 'show_posts_feed_link_logged_in_users');
function show_posts_feed_link_logged_in_users($show) {
if (is_user_logged_in()) {
return $show;
} else {
return false;
}
}
Display posts feed link only on specific pages
To display the posts feed link only on specific pages, use conditional tags like is_front_page().
add_filter('feed_links_show_posts_feed', 'show_posts_feed_link_on_front_page');
function show_posts_feed_link_on_front_page($show) {
if (is_front_page()) {
return $show;
} else {
return false;
}
}
Display posts feed link only for specific post types
To show the posts feed link only for specific post types, use the get_post_type() function.
add_filter('feed_links_show_posts_feed', 'show_posts_feed_link_for_specific_post_type');
function show_posts_feed_link_for_specific_post_type($show) {
if (get_post_type() == 'your_post_type') {
return $show;
} else {
return false;
}
}
Display posts feed link based on user role
To show the posts feed link based on the user’s role, use the current_user_can() function.
add_filter('feed_links_show_posts_feed', 'show_posts_feed_link_for_admins');
function show_posts_feed_link_for_admins($show) {
if (current_user_can('manage_options')) {
return $show;
} else {
return false;
}
}