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

2020年05月11日14:06:23 发表评论 热度480 ℃

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

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

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

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

本文最后更新于:2021-04-11 14:52
瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: