首页 > php教程 > php手册 > 正文

Append and Prepend to WordPress RSS Feed?Content

WBOY
发布: 2016-06-06 20:13:08
原创
1909 人浏览过

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学习者快速成长!