2013-06-21 60 views
0
功能

我有以下問題:遇到問題與WordPress的

我不想WP增加wpautop到所有頁面,但只有我需要的,所以我說這一點:

function my_wpautop_correction() { 
    if(is_page()) { 
     remove_filter('the_content', 'wpautop'); 
     remove_filter('the_excerpt', 'wpautop');  
    } 
    if(is_page(array(79, 81))) { 
     add_filter('the_content', 'wpautop'); 
     add_filter('the_excerpt', 'wpautop');  
    } 
} 
add_action('pre_get_posts', 'my_wpautop_correction'); 

似乎工作正常,但我不確定它是否是寫入該函數的最佳方式。我試過這個:

function my_wpautop_correction() { 
    if(!(is_page(79) || is_page(81))) { 
     remove_filter('the_content', 'wpautop'); 
     remove_filter('the_excerpt', 'wpautop');  
    } 
} 
add_action('pre_get_posts', 'my_wpautop_correction'); 

但它不工作,我做錯了什麼?我想wpautop僅添加到79和81

+0

如果你想刪除79,81頁,爲什麼你叫他們在的add_filter工作職能? – Zzz

+0

哎呀抱歉,注意到我的措辭是錯誤的。我想僅將wpautop添加到第79頁和第81頁,並將其從所有其他頁面中刪除。對困惑感到抱歉。 –

+0

使用'array()'比檢查單個頁面更清晰,[函數](http://codex.wordpress.org/Function_Reference/is_page)可以接受數組。 –

回答

1

頁試試這個:

function my_wpautop_correction() { 
    if(!is_page(79) || !is_page(81)) { 
     remove_filter('the_content', 'wpautop'); 
     remove_filter('the_excerpt', 'wpautop');  
    } 
} 
add_action('pre_get_posts', 'my_wpautop_correction'); 
+0

不,它從所有頁面中刪除過濾器。 –

+0

您需要提供其他代碼以幫助您 – Noqomo