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:
Vivo unveils new X90 series with 1-inch camera sensor · TechNode
Happy Republic Day 2023
14 Different Types of Love
BeReal: cos’è e come funziona il nuovo social che spopola in tutto il mondo - EOS Mktg&Communication
All about Digital Marketing | Simply Explained
Delivered ROI for a Singapore medtech healthcare through digital strategy consulting
How to Disable Password Change Notifications in WordPress – Growth Hacking Insights
Geely targets 600,000 EV sales in 2023 · TechNode
Happy Pongal 2023
The ENGAGE Podcast Episode 246: Future of Nonprofit Finance: Cyber Security
5 xu hướng tiếp thị tìm kiếm hàng đầu trong năm 2023
Shanghai Mayor visits three leading private firms in a day, expects them to play bigger role in cons...