LoginSignup
7
5

More than 5 years have passed since last update.

【WordPress】標準のRSSをカスタマイズして出力する

Last updated at Posted at 2016-06-06

【WordPress】標準のRSSをカスタマイズして出力する

RSS出力用のフックに引っ掛けて、独自作成したRSSテンプレートを読み込ませる

・RSSテンプレートを作成する。
今回は使用しているテーマの直下にfeedsというディレクトリを作成して、
その中に独自に作成したRSSテンプレートを格納します。
~/wordpress/wp-content/themes/任意のテーマ/feeds/feed-excite.php

独自RSSテンプレートの作成は、wordpress標準の、
~/wordpress/wp-includes/feed-rss2.php
などをコピーして編集すると作りやすいと思います。

・作成したテンプレートを読み込む
作成した独自RSSテンプレートを読み込む関数を作成し、
add_actionでアクションフックを追加する。

function.php
/*
 * 作成した独自RSSテンプレートを読み込む
 */
function do_feed_new() {
    load_template( get_template_directory() . '/feeds/feed-new.php');
}
//独自RSSテンプレート呼び出し用アクションフックを追加
add_action('do_feed_new', 'do_feed_new');

・ホームURLの最後尾に/?feed=newを指定してアクセスする。

例: http://sample_url/?feed=new

feed-new.phpに書かれた内容でRSSが出力されます。

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5