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

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


 

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

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和首页输出自定义内容。


版权声明:本文来源于互联网,如有侵权,请联系下方邮箱,一个工作日删除!