2014-11-03 71 views
-1

我使用此代码中的所有页面禁用auto paragraphbr条件语句中的functions.php不工作

remove_filter('the_content', 'wpautop'); 
    remove_filter('the_excerpt', 'wpautop'); 

后来我决定,我想汽车<p><br /> 行为是那样的,在taxonomy => blog-cat,所以我来了与此代码:

function remove_auto(){ 
if(!is_tax('blog-cat')){ 
    remove_filter('the_content', 'wpautop'); 
    remove_filter('the_excerpt', 'wpautop'); 
} 
} 
add_action('wp_head','remove_auto',0); 

但不幸的是,它不工作。

有没有人有想法?

+1

您需要提供更多信息。 – EternalHour 2014-11-03 03:50:49

+0

这对于......有什么作用? – Ohgodwhy 2014-11-03 04:05:34

回答

0

您的代码正在检查“blog-cat”是否不是每个请求的分类标准,而不是检查当前分类标准,并且不删除过滤器(如果它是“blog-cat”)。您无法使用get_queried_object()->name来获取分类名称。

function remove_auto(){ 
    // remove the filter if it is not a taxonomy, or if it is the name doesn't equal 'blog-cat' 
    if (! is_tax() || 'blog-cat' != get_queried_object()->name){ 
     remove_filter('the_content', 'wpautop'); 
     remove_filter('the_excerpt', 'wpautop'); 
    } 
} 
add_action('wp_head', 'remove_auto'); 
+0

我用你建议的代码替换我的代码,但不幸的是它不工作。但无论如何感谢您的回答... – 2014-11-03 05:59:21