How to disable wpautop in WordPress

To disable wpautop in WordPress, simply add this snippet to your child theme functions.php file:

/*disable wpautop automatic p tags*/
remove_filter( 'the_content', 'wpautop' ); /*in posts and pages*/
remove_filter( 'the_excerpt', 'wpautop' ); /*in posts and pages excerpts */
remove_filter('term_description','wpautop'); /*in category, tags and taxonomy descriptions */

In HTML, writing spaces or new lines in the code has no effect on the front-end of pages. You can add lines to facilitate the reading of the code. To insert a Line Break, you must add a <br> tag and to insert a space. To start a new Paragraph, you must add a <p></p> tag.

The difference between a Break Line and a Paragraph is the Paragraph will add a space at the bottom. It is styled as display:block; (which breaks the line) and margin-bottom:20px;.

WordPress adds <p> tags anytime you break the line in both the visual editor or the html text editor. The function is called “wpautop“. It can be very annoying when you write a post, a page or a category/term description because it will often add unnecessary <p> tags and therefore spaces to your content.

With this simple snippet WordPress will stop adding <p> tags automatically in all pages, posts, taxonomy, descriptions and excerpts but you will need to add them manually when you want to display paragraphs, even in previously published content. Alternatively you can add only this snippet to disable wpautop only in the excerpts and term descriptions and preserve your paragraphs in your pages and posts:

/*disable wpautop automatic p tags*/
remove_filter( 'the_excerpt', 'wpautop' ); /*in posts and pages excerpts */
remove_filter('term_description','wpautop'); /*in category, tags and taxonomy descriptions */

Reference: https://codex.wordpress.org/Function_Reference/wpautop

 

Do you like it?

Last Update: June 11, 2016  

June 11, 2016   174    Coding, Website    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

728x90-_0005_3-free-goods

Launch Websites with Pre-build codes from 2$

Build WordPress Websites with Drag & Drop Themes and Plugins

Reply