I’m writing a plugin to block some pages to anonymous users on my site. I already blocked some pages but I can’t get to identify the feed page my-wordpress-site.com/feed
.
I’ve tried:
$GLOBALS['pagenow'] == 'feed'
is_feed()
is_page('feed')
- checking on
$_SERVER['REQUEST_URI']
and $_SERVER['PATH_INFO']
Any ideas on how to achieve that?
You have not specified exactly when your code runs but you can hook into “request” to check the requested page:
add_filter( 'request', function( $request ){
if( isset( $request['feed'] ) ){
//This is a feed request
}
return $request;
});
When the requested page is a feed $request
, which is an array of query variables, will contain an item called “feed” which is set with the name of the feed like “rss” for example.
https://codex.wordpress.org/Plugin_API/Filter_Reference/request