2

I've tried disabling WP's auto-paragraph thingy using

remove_filter ('the_content', 'wpautop');

but I am still getting my stuff wrapped in automatic <p> tags... What am I doing wrong?

Its at the bottom of a functions file. Its not in functions.php, but in a file that functions.php includes (and putting it in functions.php doesn't change the behaviour at all).

Update: var_dump( $wp_filter['the_content'] ); outputs NULL. How can I test why this filter isn't being run?

4 Answers 4

2

Had same problem, fixed with css:

<style>
p:empty{
  height: 0;
  margin: 0;
  padding: 0;
}
</style>
1
  • This does not "fix the problem" when you have blocks of CSS or JS in the code, etc. This is not a solution, it's a hacky workaround. Aug 22, 2023 at 13:53
3

If you're using the TinyMCE Advanced plugin, try unchecking this advanced option:

Stop removing the <p> and <br /> tags when saving and show them in the HTML editor

Unchecking that and using the remove_filter ('the_content', 'wpautop'); code in my functions.php did the trick for me.

2

Your code is absolutely correct. You can try this snippet in template to ensure it is being removed:

var_dump( $wp_filter['the_content'] );

If it's not it may be that code never reaches your filter removal (return above it for example) or filter is re-added later by some other code.

14
  • 2
    or try changing the filter priority, default is 10 Jan 12, 2011 at 14:08
  • @Ambitious Amoeba not sure what you mean? Priority should match exactly for remove_filter() to work.
    – Rarst
    Jan 12, 2011 at 14:17
  • yeah, but if you add a filter with priority 20, shouldn't you remove it with the same priority? maybe autop is added with a different priority... Jan 12, 2011 at 14:36
  • @Ambitious Amoeba I've checked the source and tested code, it is added without priority specified so default it is.
    – Rarst
    Jan 12, 2011 at 14:43
  • var_dump( $wp_filter['the_content'] ); outputs NULL. I've tried grepping for wpautop but apparently none of the php files in wp-content contain this, apart from my line of code. Jan 12, 2011 at 19:13
0

My problem was while developing a shortcode. Credits to Samuel Wood. See his advice here:

Oh, and if you’re putting in shortcodes, use a shortcode block instead of typing them into a P block. Then you won’t have wrapper P tags.

https://wordpress.org/support/topic/wpautop-not-working-on-wp_editor/

1
  • So, for those of us who don't use blocks.... ???
    – John Smith
    Mar 17 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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