如何从将内容添加到单个帖子模板的过滤器中省略特定帖子?

时间:2018-08-28 20:53:15

标签: php wordpress

在functions.php中有以下过滤器,该过滤器在博客文章的末尾添加了一些内容:

div {
  background:green;
  position:fixed;
  color:#fff;
  width:50px;
  height:50px;
  top:50%;
  left:50%;
  -ms-transform: translateX(-50%) translateY(-50%);
  -webkit-transform: translate(-50%,-50%);
  transform: translate(-50%,-50%);
}

我希望能够阻止将此内容添加到特定帖子中。我可以将这些页面ID添加到上面的代码中吗?

1 个答案:

答案 0 :(得分:1)

当然! is_single()函数接受一个数组作为参数。因此,您可以执行此操作(未经测试):

function single_content_after( $content ) {
    if(is_singular('post') && !is_single(array(20, 30, 40))) {
        $content .= '<p>Foo</p>';
    }
    return $content;
}
add_filter('the_content', 'single_content_after');