WordPress「add_theme_support」でフィードリンクを有効化する

フィードとは、コンテンツの概要を配信用に加工したテキストのこと。WordPressでは以下のように説明がある。

フィードは、フィードリーダーがサイトにアクセスし、新規コンテンツを自動的に探し出し、その情報を別のサイトに投稿し更新できるようにする特別なソフトウェア機能です。この機能により、ユーザーは異なるブログに投稿された最新情報を得ることができます。

https://ja.wordpress.org/support/article/wordpress-feeds/

要約すると、フィードとは更新情報のチェックを行う機能のこと。

フィードの種類としては主に3種類挙げられる。

  • RSS(Rich Site Summary、Really Simple Syndication)
  • Atom
  • RDF ファイル

フィードに対してフィードリンクとは、ブログの更新情報について掲載するページのURLのことで、閲覧者に最新の情報を配信する事ができるようにするもの。

フィードリンクを有効化する


add_theme_support( 'automatic-feed-links' );

フィードリンクは投稿ページカテゴリーページで出力が異なる。

投稿ページのフィードリンク

フィードリンクを有効化すると、<head>内に次の1のような記事フィードリンクが出力される。


// ①
<link rel="alternate" type="application/rss+xml" title="テストサイト &raquo; フィード" href="https://example.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="テストサイト &raquo; コメントフィード" href="https://example.com/comments/feed/" />

1の記事フィードリンクを無効化する。


// ①を無効化
remove_action('wp_head', 'feed_links', 2);

カテゴリーページのフィードリンク

フィードリンクを有効化すると1に加えて、次の2のようなカテゴリーフィードが出力される。


// ①
<link rel="alternate" type="application/rss+xml" title="すなこと &raquo; フィード" href="https://example.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="すなこと &raquo; コメントフィード" href="https://example.com/comments/feed/" />
// ②
<link rel="alternate" type="application/rss+xml" title="すなこと &raquo; WordPress カテゴリーのフィード" href="https://example.com/log/wordpress/feed/" />

2のようなカテゴリーフィードリンクを無効化する。


// ②を無効化
remove_action('wp_head', 'feed_links_extra', 3);
メモ

add_theme_support('automatic-feed-links');を無効化しているにも関わらず、カテゴリーフィードリンクは出力されていた。カテゴリーフィードリンクを無効化するために、remove_action('wp_head', 'feed_links_extra', 3);を記述する必要があった

フィードリンクのURL

WordPressがサポートしているフィードリンクは5種類ある。


http://example.com/feed/
http://example.com/feed/rss/
http://example.com/feed/rss2/
http://example.com/feed/rdf/
http://example.com/feed/atom/

また別種のコメントフィードがある。


http://example.com/comments/feed/ 
http://example.com/?feed=comments-rss2
http://example.com/post-name/feed/ 
http://example.com/?p=33&feed=rss2

特定のカテゴリーとタグに絞ってフィードを取得できる。


http://www.example.com/?cat=42&feed=rss2
http://www.example.com/?tag=tagname&feed=rss2
http://www.example.com/category/categoryname/feed
http://www.example.com/tag/tagname/feed
http://www.example.com/?cat=42,43&feed=rss2
http://www.example.com/?tag=tag1,tag2&feed=rss2
http://www.example.com/category/cat1,cat2/feed
http://www.example.com/category/cat1/category/cat2/feed
http://www.example.com/tag/tag1/tag/tag2/feed
http://www.example.com/category/cat1/category/cat2/feed
// 除外
http://www.example.com/tag/tag1/tag/tag2/feed

Related Tags