The is_comment_feed() WordPress PHP function checks if the current query is for a comments feed.
Usage
$is_comment_feed = is_comment_feed();
If the current query is for a comments feed, the function returns true
. Otherwise, it returns false
.
Parameters
- None
More information
See WordPress Developer Resources: is_comment_feed
Examples
Display a message if it’s a comment feed page
This code checks if the current query is a comment feed and displays a message if it is.
if (is_comment_feed()) { echo "You are viewing a comment feed!"; }
Add custom CSS to comment feed pages
This code adds custom CSS to the head of comment feed pages.
function my_comment_feed_css() { if (is_comment_feed()) { echo '<link rel="stylesheet" href="' . get_stylesheet_directory_uri() . '/comment-feed.css">'; } } add_action('wp_head', 'my_comment_feed_css');
Redirect comment feed pages to homepage
This code redirects all comment feed pages to the homepage.
function my_redirect_comment_feed() { if (is_comment_feed()) { wp_redirect(home_url()); exit; } } add_action('template_redirect', 'my_redirect_comment_feed');
Change comment feed title
This code changes the comment feed title to a custom title.
function my_custom_comment_feed_title($title) { if (is_comment_feed()) { $title = "My Custom Comment Feed Title"; } return $title; } add_filter('wp_title', 'my_custom_comment_feed_title');
Remove comment feed link from the header
This code removes the comment feed link from the header if the current query is a comment feed.
function my_remove_comment_feed_link() { if (is_comment_feed()) { remove_action('wp_head', 'feed_links', 2); } } add_action('wp_head', 'my_remove_comment_feed_link', 1);