WordPressのフィードテンプレートをテーマディレクトリのものへ変更したいときがあります。そんなときは、functions.phpへ処理を記述してフックしましょう。次の例では、フィードテンプレートを、テーマディレクトリ配下のものに変更しています。rss2なども同様に対応可能です。
具体的には次のようにします。wp-include フォルダ内に同じ名前のファイルがありますから、これをテーマフォルダへコピーしてカスタマイズするとらくちんです。
remove_filter('do_feed_atom', 'do_feed_atom', 10);
function custom_feed_atom( $for_comments ) {
$template_file = '/feed-atom' . ( $for_comments ? '-comments' : '' ) . '.php';
$template_file = ( file_exists( get_template_directory() . $template_file )
? get_template_directory()
: ABSPATH . WPINC
) . $template_file;
load_template( $template_file );
}
add_action('do_feed_atom', 'custom_feed_atom', 10, 1);
function custom_feed_atom( $for_comments ) {
$template_file = '/feed-atom' . ( $for_comments ? '-comments' : '' ) . '.php';
$template_file = ( file_exists( get_template_directory() . $template_file )
? get_template_directory()
: ABSPATH . WPINC
) . $template_file;
load_template( $template_file );
}
add_action('do_feed_atom', 'custom_feed_atom', 10, 1);
処理自体は、;$template_file に使いたいファイル名を指定してから、そのファイルをロードししているだけです。もともとのファイル名(feed-atom.php, feed-atom-comments.php)をそのままつかって、テンプレートファイルがあるディレクトリに、同名のPHPファイルがあるなら、そちらを優先していますから、このあたりのロジックを変更すれば、ファイル名を変更することができます。
参考:
各種フィード用テンプレートの変更 : dogmap.jp
関連書籍: