Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Remove WordPress <br /> Tags On Pages ONLY WordPress

  • SOLVED

I'm looking to remove the functionality where WP adds <br /> 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 <br />'s but JUST for pages?

Any ideas?

Answers (2)

2010-04-24

Andrzej answers:

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');


jason.narciso comments:

Andrezj,

That second option seems to be working exactly how I need. Thank you! I'm also assuming that if I want to single out one particular page, I can just code it like this:

function my_wpautop_correction() {

if( is_page("page-name") ) {

remove_filter( 'the_content', 'wpautop' );

remove_filter( 'the_excerpt', 'wpautop' );

}

}

add_action('pre_get_posts', 'my_wpautop_correction');


Thanks again, looks like you are the winner of this thread. (Love this site/service, by the way.)

2010-04-23

Michael Fields answers:

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' );
}