is_comment_feed()
Checks if the request is a comment feed page. Conditional tag.
Uses the global variable $wp_query.
Works based on the method WP_Query::is_comment_feed.
1 time — 0.000016 sec (very fast) | 50000 times — 0.02 sec (speed of light) | PHP 7.1.2, WP 4.7.3
No Hooks.
Returns
true|false. true when we are on an RSS or other comment feed page.
Usage
if( is_comment_feed() ){
// comment feed page.
}
Examples
#1 Close the comment feed
add_action( 'wp', 'close_comment_feed' );
function close_comment_feed() {
if ( is_comment_feed() ) {
wp_die( 'Comments are closed.', '', [ 'response' => 403 ] );
}
}
Notes
- Global. WP_Query.
$wp_queryWordPress Query object.
Changelog
| Since 3.0.0 | Introduced. |
is_comment_feed() is comment feed code WP 6.9.1
function is_comment_feed() {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_comment_feed();
}