簡體   English   中英

在Wordpress中遇到功能問題

[英]Having trouble with a function in 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頁。

嘗試這個:

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');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM