【问题标题】:target specific wordpress page template with functions.php使用functions.php定位特定的wordpress页面模板
【发布时间】:2016-12-01 22:42:46
【问题描述】:

我正在尝试针对特定的页面模板,即具有以下功能的 single.php 文件,以根据页面模板是否为 single.php 来停用内容或摘录上的 wpautop - 尽管我没有得到它的工作:

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

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    我想这就是你要找的东西:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      相关资源
      最近更新 更多