Tag Archives: wordpress

WordPress logo

WordPress, stop inserting HTML into posts and pages!

I like to have control over all the formatting in whatever I produce — websites, documents, slideshows. This is why I write all my posts in WordPress’ text editor. I add in all the necessary HTML formatting myself. No WYSIWYG, thank you very much.

However, WordPress does this really annoying thing where it will wrap every block of text it perceives to be a paragraph in <p> tags. The key word is “perceives”, because it also wraps images, lists, and very non-paragraphy things in <p> tags. Even more frustrating is that there is no option within WordPress’ dashboard to change this setting!

BUT, we can stop this behaviour! All it takes is these two lines of code:

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

Insert them into your theme’s or child theme’s function.php*, and tada! Auto <p> production gone for good (until you remove those two lines from your function.php, of course).

*If you’re using a child theme and it doesn’t have a function.php, just make a new text file in your child theme’s folder and call it function.php. You don’t need to copy all the code from the parent theme’s function.php. WordPress will call whatever is written in the child’s function.php, and then whatever is in the parent’s function.php, so you won’t miss out on anything.