Php 如何指定;移除"过滤器"(';内容';,';wpautop';)&引用;对于wordpress中的某些类别?

Php 如何指定;移除"过滤器"(';内容';,';wpautop';)&引用;对于wordpress中的某些类别?,php,wordpress,Php,Wordpress,我使用下面的代码来应用remove_filter('the_content','wpotp');到某些类别,但不起作用 移除_过滤器(“_内容”,“wp自动”); 添加过滤器(“内容”、“我的自定义格式”) } }很抱歉,这不是一个确切的答案,但这里有一个单一类别的解决方案,可能会引导您走上正确的道路。它将wpautop从名为“mycat”的类别中删除。我发现您的帖子正在寻找类似的解决方案,并解决了它,我想我会分享它,因为我在其他地方没有看到过它(尽管我确信其他人一定在使用它) 将其添加到fun

我使用下面的代码来应用remove_filter('the_content','wpotp');到某些类别,但不起作用

移除_过滤器(“_内容”,“wp自动”); 添加过滤器(“内容”、“我的自定义格式”)

}
}

很抱歉,这不是一个确切的答案,但这里有一个单一类别的解决方案,可能会引导您走上正确的道路。它将wpautop从名为“mycat”的类别中删除。我发现您的帖子正在寻找类似的解决方案,并解决了它,我想我会分享它,因为我在其他地方没有看到过它(尽管我确信其他人一定在使用它)

将其添加到functions.php(或root的custom.php)

function my_custom_formatting($content){

global $post; $post_id =  $post->ID; 
$post_categories = wp_get_post_categories( $post_id );
            $cats ="";
            $cats = array();

        foreach($post_categories as $c){
               $cat = get_category( $c );
               $cats['cat_id'][] = $cat->cat_ID;
         }

        $catarray=array(353, 181, 7, 176, 4, 12);
        if( count($cats['cat_id']) > 0){
           $intersectcommn_count =  count(array_intersect($catarray, $cats['cat_id']));
           if($intersectcommn_count > 0){


      return wpautop($content);

           }
//remove wpautop from "mycat" pages
function remove_autop_for_category( $content )
{
    $category = get_the_category(); 
    'mycat' === $category[0]->cat_name && remove_filter( 'the_content', 'wpautop' );
    return $content;
}
add_filter( 'the_content', 'remove_autop_for_category', 0 );