5

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 );
  • 1
    This is f* nightmare, wpautop is done in Javascript now and nobody seems to now how to disable it. wordpress.org/support/topic/… – leonbloy Sep 7 '15 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 Sep 9 '15 at 1:52
  • @shea this is correct and anything else didn't worked to me. Many thanks. – Miloš Đakonović Jun 18 '17 at 8:03
6

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.

  • 10
    This is the correct answer. The reason that the code in the question doesn't work, is that when removing a filter or action, you also have to specify the same priority. When wpautop is added, it's priority is not specified, which defaults to 10. – Eric Holmes Sep 8 '15 at 13:27
  • 2
    I think it'd be more accurate to say that your comment is the correct answer, as it gives the explicit reason... – bonger Sep 9 '15 at 23:14
6
+100

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.