首頁 > php教程 > php手册 > 主體

Append and Prepend to WordPress RSS Feed?Content

WBOY
發布: 2016-06-06 20:13:08
原創
1908 人瀏覽過

The?awesome part of RSS is that it lets you pull content wherever you want. ?The bad part, as a publisher, is that the user may be missing out on important information that is on the site but doesnt?display in articles. ?WordPress?hook sys

The?awesome part of RSS is that it lets you pull content wherever you want. ?The bad part, as a publisher, is that the user may be missing out on important information that is on the site but doesn’t?display in articles. ?WordPress’?hook system?to the rescue!

The PHP

We’re going to hook onto the the_content and?the_excerpt_rss function hooks to append or prepend content to feed entries:

// Additional RSS Content
$rss_more_content = 'blah blah blah';
$rss_more_position = 'before'; // or "after"
// Function which adds content to RSS entries
function add_rss_content($content) {
	global $rss_more_position, $rss_more_content;
	if(is_feed()) {
		if ($rss_more_position == 'before') {
			$content = "$rss_more_content\n$content";
		} else {
			$content .= "$rss_more_content\n";
		}
	}
	return $content;
}
// Add hooks
add_filter('the_content', 'add_rss_content');
add_filter('the_excerpt_rss', 'add_rss_content');
登入後複製

The only conditional is whether or not you want the content added at the top or bottom of the content block. ?This function should go into your functions.php file, but how you pull in the additional content?in is up to you!

Read the full article at: Append and Prepend to WordPress RSS Feed Content

Treehouse
Wufoo

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!