【问题标题】:Wordpress disable autoparagraph using shortcodeWordpress 使用简码禁用自动段落
【发布时间】:2014-11-02 12:40:38
【问题描述】:

我试图只在一页上禁用wpautop 功能。我尝试通过在页面中添加 [wpdisableautop] 短代码来做到这一点,但它不起作用。简码未在页面上显示为原始文本,这意味着 Wordpress 捕获了简码但它不执行任何操作。

到目前为止我做了什么:

添加到functions.php:

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

然后我在 /vnc2/ 目录中创建了一个 disableautop.php 文件:

<?php
function disableautop () {
remove_filter( 'the_content', 'wpautop' );
}
?>
  • 我不想在functions.php中全局禁用它
  • 我不想使用任何插件

我做错了什么?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    包含短代码不起作用,因为 the_content 已经运行。您最好将其添加到您的 functions.php 并使用wp_head 运行它。比如:

    function remove_autop() {
        if ( is_page( ID_HERE ) ) {
            remove_filter( 'the_content', 'wpautop' );
        }
    }
    add_action( 'wp_head', 'remove_autop');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-19
      相关资源
      最近更新 更多