I'm familiar with this little trick already for removing auto paragraph formatting in WordPress:
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
...however adding this in functions.php removes paragraphs for the entire site. This is not what I want since the client needs to be able to make edits themselves (the paragraph formatting really helps them out on posts).
Where the auto paragraph insertions are particularly damaging is on the client's home page, where there are javascript snippets. So ideally, I would like to disable auto p formatting for this page alone, or all pages if necessary, and leave posts alone.
Any ideas? I can provide more information if needed.
Thanks in advance!
Edit:
Plugins I've tried: Php Exec, Raw HTML, Disable WordPress Autop, PS Disable Auto Formatting, Toggle wpautop
You should be able to check if the template being rendered is a page using is_page(), and then optionally run the filter. We hook into 'wp_head'
, so that we can run the check before the_content
is called.
Example:
function remove_p_on_pages() {
if ( is_page() ) {
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_excerpt', 'wpautop' );
}
}
add_action( 'wp_head', 'remove_p_on_pages' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With