最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp autop - New method to disable wpautop after WP 4.3?

programmeradmin1浏览0评论

After WordPress 4.3, the old method of disabling wpautop no longer works. Has anyone discovered a new method for removing this function?

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

After WordPress 4.3, the old method of disabling wpautop no longer works. Has anyone discovered a new method for removing this function?

remove_filter( 'the_content', 'wpautop', 99 );
remove_filter( 'the_excerpt', 'wpautop', 99 );
Share Improve this question edited Sep 2, 2015 at 15:32 Robert hue 8,5662 gold badges34 silver badges50 bronze badges asked Sep 2, 2015 at 15:30 C4talystC4talyst 791 silver badge2 bronze badges 3
  • 1 This is f* nightmare, wpautop is done in Javascript now and nobody seems to now how to disable it. wordpress/support/topic/… – leonbloy Commented Sep 7, 2015 at 1:15
  • 2 @Eric Holmes is correct that the method mentioned in the question will never work as remove_filter must specify the same priority when the hook was registered with add_filter, which in this case is 10, not 99 – shea Commented Sep 9, 2015 at 1:52
  • @shea this is correct and anything else didn't worked to me. Many thanks. – Miloš Đakonović Commented Jun 18, 2017 at 8:03
Add a comment  | 

3 Answers 3

Reset to default 7

I guess you don't use it at all, so why don't you just remove the filter?

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

I've tested it a few minutes ago (on WP 4.3) and it works.

p.s. I just saw that you use the same function. Sorry for that. What version are you using? This disables the wpautop on 4.3.

On the javascript side, as a crude measure you could just replace the wp.editor.autop and wp.editor.removep with no ops:

add_action( 'admin_print_footer_scripts', function () {
    ?>
    <script type="text/javascript">
    jQuery(function ($) {
        if (typeof wp === 'object' && typeof wp.editor === 'object') {
            wp.editor.autop = function (text) { return text; };
            wp.editor.removep = function (text) { return text; };
        }
    });
    </script>
    <?php
}, 100 );

However on very limited testing although it seems to keep markup it does put it all on one line in the Text editor, which is pretty ugly...

This works well. It's about the priority of the hook :

add_filter( 'the_content', 'njengah_remove_autop', 0 );

function njengah_remove_autop($content) {

        // remove autop 

         remove_filter( 'the_content', 'wpautop' );


        return $content;
}
发布评论

评论列表(0)

  1. 暂无评论