【コピペ用】WordPressのRSSフィードを無効化する

色々な理由で、WordpressのRSSフィードを無効化したい場合があると思うんですが、その際にプラグインなどを使わなくてもfunctions.phpにコピペするだけでRSSを無効化できる方法を自分用に書き残しておきます。

テーマフォルダ内のfunctions.php(/wp-content/(利用中のテーマ)/functions.php)の末尾に、下記コードをコピペすることで、RSSフィードを無効化します。

/**
 * ------------------------------------------------------------
 * RSS無効化
 */

// それぞれのフィードを無効化
function disable_all_feeds()
{
	status_header(404);
	nocache_headers();
	header('Content-Type: text/plain');
	echo '404 Not Found.';
	exit();
}
add_action('do_feed', 'disable_all_feeds', 1);
add_action('do_feed_rdf', 'disable_all_feeds', 1);
add_action('do_feed_rss', 'disable_all_feeds', 1);
add_action('do_feed_rss2', 'disable_all_feeds', 1);
add_action('do_feed_atom', 'disable_all_feeds', 1);
add_action('do_feed_rss2_comments', 'disable_all_feeds', 1);
add_action('do_feed_atom_comments', 'disable_all_feeds', 1);

// フィードのリンクを削除
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);

簡単ですね!キャッシュプラグインを使っているときや、CDNを使っているときはそれぞれのキャッシュ削除を忘れずに…

質問・コメントなどあると嬉しいです