WordPress automatically inserts <p> </p> and <br /> tags in the “Text” section in your posts and pages. When you are writing any codes or in some situations it becomes very annoying when you get <p> </p> and <br /> tags automatically filled in your posts. To disable this feature, open the functions.php file of your WordPress theme. Add the below given lines of code:
remove_filter( ‘the_content’, ‘wpautop’ );
remove_filter( ‘the_excerpt’, ‘wpautop’ );
That’s it. WordPress will not automatically put <p> </p> and <br /> tags in your posts and pages.
Note: If you are still facing the same problem, even after you made the above changes. Simply trash the post which you were working on and create a new one. That will solve it.
Yup, that solution works, but removes all paragraphs entirely from the site – even if on some pages / posts you need them. Any suggestions on toggling this feature for specific pages / posts?
The reason I ask is we need the auto p function removed for literally one page because it’s breaking some javascript code. All of the other pages where is inserted is fine.
TIA!
You can try this WordPress plugin. By using this plugin you can control automatic insert of paragraph and line break tags on a per post basis.
Yea, I’d definitely say out of all of the plugins I’ve tried, that one is the best. Another suggestion I got from a developer that works on other themes is if none of the other plugins work, just try custom coding it into functions.php, like this:
function remove_p_on_pages() {
if ( is_page() ) {
remove_filter( ‘the_content’, ‘wpautop’ );
remove_filter( ‘the_excerpt’, ‘wpautop’ );
}
}
add_action( ‘wp_head’, ‘remove_p_on_pages’ );
…this way the page looks through the check in the section first before the WP filters take effect, in this case by seeing if the document is a page or not, and if it is, run the filter.
Unfortunately I had to get stuck with a buggy theme and had to email the devs on this one because nothing works, but hopefully they can help. Thank you too for your comments and for the post, you helped me on the right track!
You are most welcome! I am glad the post was helpful.