2016-07-27 7 views
0

特定のページテンプレート、以下の機能を持つsingle.phpファイルをターゲットにしようとしています。ページテンプレートが単一であるかどうかに応じてコンテンツのwpautopを非アクティブ化するか、 .php - 私はそれが働くようにはなっていません:functions.phpを指定した特定のWordPressページテンプレート

function rem_filter() { 
    if (is_page_template('single.php')) 
    { 
     remove_filter('the_content', 'wpautop'); 
    } else { 
     remove_filter('the_excerpt', 'wpautop'); 
    } 
} 
add_action ('wp_enqueue_scripts', 'rem_filter'); 

すべての助けがありがたいです。

Wordpress use functions.php to run function only on specific page template

感謝:私は質問をする前に、フォーラムでこれを見つけました!

/K私は、これはあなたが探しているものだと思う

答えて

0

remove_filter('the_content', 'wpautop'); 
remove_filter('the_excerpt', 'wpautop'); 

//decide when you want to apply the auto paragraph 

add_filter('the_content', 'my_custom_content'); 
function my_custom_content($content){ 
    if(is_page_template('single.php')){ 
     return $content; //no autop 
    }else{ 
     return wpautop($content); 
    } 
} 

add_filter('the_excerpt', 'my_custom_excerpt'); 
function my_custom_excerpt($content){ 
    if(is_page_template('single.php')){ 
     return $content; //no autop 
    }else{ 
     return wpautop($content); 
    } 
} 
関連する問題