2014-11-03 70 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