Horje
Remove WordPress
Tags On Pages ONLY - Wordpress Solution
[Solved] - Remove WordPress
Tags On Pages ONLY - Wordpress Solution
Try following codes
I'm looking to remove the functionality where WP adds
tags but ONLY on Pages, not Posts. So in formatting.php I've learned that if you change
function wpautop($pee, $br = 1) {
to
function wpautop($pee, $br = 0) {
this will work. BUT, when I try to create just a single line return when creating posts it does not work. Is there a way to single out auto
's but JUST for pages? Any ideas?

Solution - 1

I think author wants to remove this br-s from pages, your approach seems to work on posts? Also, removing whole 'wpautop' filter kills all wordpress formating like p tags, if you want to remove just the br tags, you might try adding this to your functions.php file in theme folder:

function my_wpautop_correction() {	
	if( is_page() ) {		
		function my_wpautop( $pee ) {
			return wpautop($pee, 0);
		}		
		remove_filter( 'the_content', 'wpautop' );
		remove_filter( 'the_excerpt', 'wpautop' );		
		add_filter( 'the_content', 'my_wpautop' );		
		add_filter( 'the_excerpt', 'my_wpautop' );		
	}
}
add_action('pre_get_posts', 'my_wpautop_correction');
If you however want to remove all wordpress formating from pages only you might try this:
function my_wpautop_correction() {	
	if( is_page() ) {		
		remove_filter( 'the_content', 'wpautop' );
		remove_filter( 'the_excerpt', 'wpautop' );			
	}
}
add_action('pre_get_posts', 'my_wpautop_correction');


Solution - 2

Try this in your functions.php file:

add_action( 'pre_get_posts', 'mfields_remove_autop_from_posts' );
function mfields_remove_autop_from_posts() {
	if( !is_page() && !is_attachment() )
		remove_filter( 'the_content', 'wpautop' );
}

Date: 2022-10-21 05:22:42
Category: Wordpress
More for You