How to Remove or Disable autop In WordPress Posts & Custom Post Types

remove autop in WordPress

If you are looking for the best way to remove automatically added paragraph tags in WordPress, you can get this done using a remove_filter() action. T

here are also plugins that help to remove autop in WordPress.

I think this is a small issue that does not require a plugin to be installed. You can remove autop tags by adding this small remove_filter() action hook and it works.

Remove autop in WordPress Steps

  1. Login into your WordPress site
  2. Open the theme editor under the Appearance menu and in your active theme open the functions.php file. You can also use the FTP or Cpanel to access the file.
  3. Add the remove_filter() hook for example : remove_filter( 'the_content', 'wpautop' );
  4. Save the changes and check the frontend you have successfully removed the autop tags from WordPress post or pages or custom post types.

Here are the code snippets that you should add to the functions.php to disable autop in WordPress. The basic remove filter code is as follows :

remove_filter (‘the_content’, ‘wpautop’);
remove_filter (‘the_excerpt’, ‘wpautop’);

Remove Autop In Posts & Pages

Use the code snippet below to remove the WordPress autop in either posts or pages:

add_filter( 'the_content', 'njengah_remove_autop', 0 );

function njengah_remove_autop($content) {

// remove autop

remove_filter( 'the_content', 'wpautop' );


return $content;
}

Remove WordPress Autop In Excerpt

Use the code snippet below to remove the WordPress autop in excerpts on archives or category pages:

add_filter( 'the_excerpt', 'njengah_remove_autop', 0 );

function njengah_remove_autop($content) {

// remove autop

   remove_filter( 'the_content', 'wpautop' );


return $content;
}

Remove WordPress Autop In Custom Post Types

Use the code snippet below to remove the WordPress autop in the custom post types;

add_filter( 'the_excerpt', 'njengah_remove_autop', 0 );

function njengah_remove_autop($content) {

// remove autop

'post-type' === get_post_type() && remove_filter( 'the_content', 'wpautop' );


return $content;
}

Remove WordPress Autop in Specific Page

Use the code snippet below to remove the WordPress autop on a specific page using the is_page() conditional function.

add_filter ('the_content', 'njengah_remove_autop', 9);

function njengah_remove_autop ($content) {

if (is_page ('name of page')) {
	
     remove_filter ('the_content', 'wpautop');
	 
		return $ content;
	
     } else {
		 
		return $ content;
    }
	
}

 

Similar Articles

Comments are closed.