在所有WordPress文章底部添加自定义内容

wp教程评论1.1K views阅读模式

有时候,你可能需要在所有文章底部添加自定义内容,可以将下面的代码添加到主题的 functions.php 文件中:

1
2
3
4
5
6
7
8
function add_after_post_content($content) {
	if(!is_feed() && !is_home() && is_singular() && is_main_query()) {
		$content .= '你需要添加的自定义内容';
	}
	return $content;
}
add_filter('the_content', 'add_after_post_content');

//在所有文章底部添加自定义内容 function add_after_post_content($content) { if(!is_feed() && !is_home() && is_singular() && is_main_query()) { $content .= '你需要添加的自定义内容'; } return $content; } add_filter('the_content', 'add_after_post_content');

第 3 行代码使用了条件标签,禁止Feed和首页输出自定义内容。

关于条件标签,你可以看看:WordPress条件标签(Conditional Tags)

企鹅博客
  • 本文由 发表于 2020年8月8日 23:14:32
  • 转载请务必保留本文链接:https://www.qieseo.com/31409.html

发表评论