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

时间:2019-08-29   阅读:538

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

1
2
3
//在所有文章底部添加自定义内容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)


上一篇:修改WordPress搜索结果的链接样式

下一篇:让WordPress每篇文章的发布时间至少间隔1小时

网友评论