remove_filter (‘the_content’, ‘wpautop’);
remove_filter (‘the_excerpt’, ‘wpautop’);
Disable Wpautop on Certain Pages
Use the following code snippet instead if you want to disable this feature on a specific page only. In line 3, specify the URL or the ID of the page you want to disable.
add_filter ('the_content', 'specific_no_wpautop', 9); function specific_no_wpautop ($ content) { if (is_page ('name of page')) { remove_filter ('the_content', 'wpautop'); return $ content; } else { return $ content; } }
Disable Wpautop in Custom Post Types
To disable automatic p-tags for custom post types, you can simply use the following code snippet:
add_filter( 'the_content', 'disable_wpautop_cpt', 0 ); function disable_wpautop_cpt( $content ) { 'custom_post_slug' === get_post_type() && remove_filter( 'the_content', 'wpautop' ); return $content; }
Disable Wpautop and List Exceptions
In this code snippet, we list exceptions in the following ways:
/** * Allow or remove wpautop based on criteria */ function conditional_wpautop($content) { // true = wpautop is ON unless any exceptions are met // false = wpautop is OFF unless any exceptions are met $wpautop_on_by_default = true; // List exceptions here (each exception should either return true or false) $exceptions = array( is_page_template('page-example-template.php'), is_page('example-page'), ); // Checks to see if any exceptions are met // Returns true or false $exception_is_met = in_array(true, $exceptions); // Returns the content if ($wpautop_on_by_default==$exception_is_met) { remove_filter('the_content','wpautop'); return $content; } else { return $content; } } add_filter('the_content', 'conditional_wpautop', 9);
Remove Empty Paragraphs Already Added by WordPress
Copy-paste this into your functions.php
file (source – GitHub):
/** * Remove empty paragraphs created by wpautop() * @author Ryan Hamilton * @link */ function remove_empty_p( $content ) { $content = force_balance_tags( $content ); $content = preg_replace( '#<p>\s*+(<br\s*/*>)?\s*</p>#i', '', $content ); $content = preg_replace( '~\s?<p>(\s| )+</p>\s?~', '', $content ); return $content; } add_filter('the_content', 'remove_empty_p', 20, 1);
Disable Automatic Paragraph Tags with Plugin
The following plugins can be used as well to disable the use of P tags on your website:
- Toggle wpautop
- Disable Automatic P Tags
- Empty P Tag
Source link
Related posts:
Geely’s luxury EV brand Lotus to go public on Nasdaq · TechNode
10 Ideas for Improving your Content Marketing ROI
Press: McDonald's Launches a Whole New Kind of Restaurant - Brian Solis
A Digital Marketing Guide for Beginners | Koozai
Conoce la tendencia Phygital (DiPhy), una nueva experiencia del retail - Brian Solis
Maybe You Didn't Realize How Much You Light Up Everyone Around You - Brian Solis
Samadhan, Samridhi, Abhay, Sah-astitva as comprehensive Human Goals
8 FREE Websites To Learn Digital Marketing!
Top Social Media Marketing Trends for 2023 | Cooler Insights
Check Website Speed: How to Master Google's New "Fast Page" Label
The Awards Magazine Names Brian Solis as a Top 100 Global Thought Leader on Technology to Follow in ...
Real Estate Investment Trust