How to Disable / Stop RSS Feeds in WordPress
Anyone who uses Wordpress may want to stop RSS feeds to stop spammers and scammers. The common approach is the following function added to functions.php :
function fb_disable_feed() {
wp_die( __(‘No feed available,please visit our homepage!’) );
}
add_action(‘do_feed’, ‘fb_disable_feed’, 1);
add_action(‘do_feed_rdf’, ‘fb_disable_feed’, 1);
add_action(‘do_feed_rss’, ‘fb_disable_feed’, 1);
add_action(‘do_feed_rss2, ‘fb_disable_feed’, 1);
add_action(‘do_feed_atom’, ‘fb_disable_feed’, 1);
What's wrong this function?
Well, it returns a HTTP Status code of 500.
| 500 (Internal server error) | The server encountered an error and can't fulfill the request. |
Not terribly SEO friendly. Too many 500 errors call into question the reliability of that site. Google doesn’t want to send users to a site that ultimately times out and doesn’t load.
// Remove feed links from the header add_action( 'wp_head', 'custom_remove_feed_links', 1 ); function custom_remove_feed_links() { // Remove feed links from the header remove_action( 'wp_head', 'feed_links', 2 ); remove_action( 'wp_head', 'feed_links_extra', 3 ); } // Redirect all feed requests to the homepage foreach ( array( 'rdf', 'rss', 'rss2', 'atom' ) as $feed ) { add_action( 'do_feed_' . $feed, 'custom_redirect_feeds', 1 ); } unset( $feed ); function custom_redirect_feeds() { wp_redirect( home_url(), 302 ); exit(); } // Delete feed rules add_action( 'init', 'custom_kill_feed_endpoint', 99 ); function custom_kill_feed_endpoint() { global $wp_rewrite; $wp_rewrite->feeds = array(); flush_rewrite_rules(); // Delete this line after running once }
No comments:
Post a Comment