【问题标题】:Conditional "the_content" filter wordpress有条件的“the_content”过滤器wordpress
【发布时间】:2017-01-10 10:23:36
【问题描述】:

我在functions.php中为“the_content”添加了一个过滤器

add_filter ('the_content', 'testFilter');
function testFilter($content) {
  if(is_single()) {
    $content.="Append content";
  }
  return $content;
} 

现在在我的 content-post.php 中。我有以下行:

the_content(__('Test;', 'tag') );

如何将 testFilter 排除在 content-post.php 页面上?

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案1】:

    在你的函数the_content(__('Test;','tag'))上方添加remove_filter函数。

    remove_filter( 'the_content', 'testFilter',11 );
    the_content(__('Test;', 'tag') );
    

    【讨论】:

    • 我看到您已将第三个参数设置为 11,它的优先级... 11 的任何具体原因?
    • 优先级。默认情况下它设置为 10。所以我将优先级添加到 11。
    • 谢谢..我会添加这个供我参考codex.wordpress.org/Function_Reference/remove_filter
    • add_actionremove_action 的第三个参数,正如您已经确定的那样,是优先级。但请务必注意,您不能删除优先级与添加时不同的过滤器。
    猜你喜欢
    • 2013-01-19
    • 2012-11-28
    • 2012-01-22
    • 2011-07-10
    • 1970-01-01
    • 1970-01-01
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多