Wordpress如果is_page功能不起作用

时间:2012-12-31 03:29:49

标签: php wordpress

我正在尝试为我的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);

1 个答案:

答案 0 :(得分:1)

你可能在循环中使用它。 is_page()仅在循环外部工作。

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