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
- Login into your WordPress site
- 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.
- Add the remove_filter() hook for example :
remove_filter( 'the_content', 'wpautop' );
- 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; } }
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Create Number Pagination in WordPress Without Using Plugin
- How to Insert Default Content to WordPress Post Editor Dynamically
- How to Remove WordPress Admin Menu Items Programmatically Without Plugin
- How to Select All Except Last Child In CSS » CSS Not Last Child Example
- How to Get Logged In User Information in WordPress
- How Add Text Before the Price in WooCommerce » Add Text Before Price
- How to Remove Zoom Effect on WooCommerce Product Image
- How to Remove or Disable Reviews In WooCommerce
- How to Redirect to Cart after Login in WooCommerce
- 5 WordPress Pagination Code Snippets with Examples [Simple to Advanced]
- How to Remove or Hide Comments from Custom Post Type » Disable Comments in Custom Post Types
- How to Quickly Find Page ID in WordPress or Post ID
- How to Display Category Name in WordPress Using a Practical Example
- How to Get Post ID by Slug in WordPress With a Practical Example
- How to Add Description after Price in WooCommerce
- How to Create WordPress Pagination for Custom Post Types
- How to Remove Related Products in WooCommerce in 3 Easy Options
- How to Skip Cart and Redirect to Checkout Page WooCommerce
- How to Disable Specific Plugin Updates In WordPress
- How to Remove Has Been Added to Your Cart Message WooCommerce
Comments are closed.