2013-06-21 3 views
0
의 기능에 문제가

나는 다음과 같은 문제가 : 나는 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'); 

그러나 그것은 나던가 잘못된거야? 난 단지 페이지 79 및 81

+0

당신은 페이지 79, 81을 제거하려는 경우, 당신은 왜 작업 기능에 그들에 add_filter를 호출합니까? – Zzz

+0

죄송합니다. 내 문언이 잘못되었음을 확인했습니다. 79 페이지와 81 페이지에만 wpautop을 추가하고 다른 모든 페이지에서 제거하고 싶습니다. 혼란을 드려 죄송합니다. –

+0

'array()'를 사용하는 것은 개별 페이지를 검사하는 것보다 깔끔하고 [함수] (http://codex.wordpress.org/Function_Reference/is_page)는 배열을 받아 들일 수 있습니다. –

답변

1

에 wpautop 추가하려는 시도이 :

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