3

我正在尝试向我的 Wordpress 主题添加一个功能,该功能将在每个帖子之前和之后添加内容,但不在任何页面上。这似乎不起作用,但不知道为什么。

if(!is_page()) {
  function custom_content($content) {
    $content = 'before post content' . $content . 'after post content';
    return $content;
  }
  add_filter('the_content','custom_content');
}

编辑:我最终得到的解决方案对我有用,is_single只包含在单个帖子中。如果您想包含在单个页面上,请使用is_singular

function custom_content($content) {
    if (is_single()) {
        $content = 'before post content' . $content . 'after post content';
 }
    return $content;
}
add_filter ('the_content', 'custom_content', 0);
4

1 回答 1

1

您可能在循环中使用它。is_page() 仅在循环外有效。

https://codex.wordpress.org/Function_Reference/is_page

于 2013-01-10T21:20:46.460 回答