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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘