How To Prevent WordPress from Applying wpautop to a Page or Post
erics, Posted November 19th, 2019 at 1:56:03pm
All credit to Graham Walters for this excellent plugin and post, upon which this post is based – thank you, sir!
https://grahamwalters.me/lab/disable-wpautop-on-specific-postspages/
Recently, a client was having problems using a plugin called by a shortcode. As it turned out, the JavaScript embedded in the returned content was being broken by the WordPress auto-paragraph feature known as wpautop
.
Thank to a bit of research, I found the following solution, recorded here in case the original blog post becomes unavailable.
- Create the file
wp-content/plugins/disable-wpautop/disable_wpautop.php
based on the code below the procedure. - WordPress » Admin » Plugins » Activate “Disable wpautop”
- Go to the page or post to disable the auto-paragraph feature on
- If the Screen Options tool is not visible below, locate the Screen Options button in the upper right corner, open it and check the box labeled Custom Fields.
- Locate the Custom Fields tool box below, and inside of it the header “Add New Custom Field:”, and under that click on “Enter New”.
- Enter
wpautop
as the Name, andfalse
as the Value, then click the “Add Custom Field” button. - Click the ‘Update’ button to save the settings.
1 2 3 4 |
cd wp-content/plugins/ mkdir disable-wpautop cd disable-wpautop vi disable_wpautop.php |
wp-content/plugins/disable-wpautop/disable_wpautop.php
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?php /* * Plugin Name: Disable wpautop * Plugin URI: https://grahamwalters.me/2014/03/07/disable-wpautop-on-specific-postspages/ * Author: Graham Walters * Author URI: https://grahamwalters.me * Version: 1.1 * Description: Disable wpautop on posts/pages with custom field 'wpautop' == false. */ function custom_wpautop($content) { if (get_post_meta(get_the_ID(), 'wpautop', true) == 'false') return $content; else return wpautop($content); } remove_filter('the_content', 'wpautop'); add_filter('the_content', 'custom_wpautop'); |
Leave Your Comment
All fields marked with "*" are required.