dounangshen6553 2014-11-02 12:40
浏览 46
已采纳

Wordpress使用短代码禁用自动范围

I am trying to disable wpautop function only on one page. I tried to do this by adding a [wpdisableautop] shortcode to the page, but it did not work. Shortcode is not displaying as raw text on the page, meaning that Wordpress catches the shortcode but it does not do anything.

What I have done so far:

Added to functions.php:

<?php
include ( WP_CONTENT_DIR .'/themes/vnc2/disableautop.php');
add_shortcode( 'wpdisableautop', 'disableautop' );
?>

And then I have created a disableautop.php file inside /vnc2/ dir:

<?php
function disableautop () {
remove_filter( 'the_content', 'wpautop' );
}
?>
  • I do not want to disable it globally in functions.php
  • I do not want to use any plugins

What have I done wrong?

  • 写回答

1条回答 默认 最新

  • douwen1213 2014-11-02 13:40
    关注

    Including a shortcode won't work, because the the_content has already run. You're better off adding it to your functions.php and running it with wp_head. Something like:

    function remove_autop() {
        if ( is_page( ID_HERE ) ) {
            remove_filter( 'the_content', 'wpautop' );
        }
    }
    add_action( 'wp_head', 'remove_autop');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输