Wordpress adds extra paragraph tag

Maybe I just don’t know how to use WP editor but for some reason Wordpress adds unwanted paragraph tag. The odd thing is that this empty p tag won’t show up in Firefox and IE but every other browsers show it and screw up the page.

Editor:

[box]

Title

Lorem ipsum..

[/box]

Faulty Browser:

Title

Lorem ipsum..

So is [box] a shortcode you’re using? What does the function look like for the shortcode?

Add this in your theme’s functions.php file

remove_filter(‘the_content’, ‘wpautop’);

Hopefully this will work. :smiley:

Add this in your theme's functions.php file

remove_filter(‘the_content’, ‘wpautop’);

Hopefully this will work. :smiley:

This totally worked! Many thanks! :slight_smile:

function remove_wpautop( $content ) { 
	$content = do_shortcode( shortcode_unautop( $content ) ); 
	$content = preg_replace( '#^<\/p>|^
|

$#', '', $content ); return $content; }

You’d use it like this:

remove_wpautop($content)

wouldn’t that code remove the formating for all post content or am I missing something?

I just slap

$content = preg_replace(’#^</p>|

$#’, ‘’, $content);

into the shortcod function before the return and it does the trick.

If you’re building a theme, you don’t want to really strip out the user’s ability to use WordPress’s auto formatting. One thing you can do is create a shortcode your buyers can use to allow them to temporarily escape auto formatting.

See #9 on this post:

http://www.catswhocode.com/blog/10-incredibly-cool-wordpress-shortcodes

So, using the above example you’d do:

[raw]

[box]

Title

Lorem ipsum..

[/box] [box]

Title

Lorem ipsum..

[/box] [box]

Title

Lorem ipsum..

[/box] [/raw]
If you're building a theme, you don't want to really strip out the user's ability to use WordPress's auto formatting. One thing you can do is create a shortcode your buyers can use to allow them to temporarily escape auto formatting.

Yep, this seems to be best solution. Thanks.

This worked for me as well! Thanks a million!

Wow, removing autop is a sure way to make a few enemies. Unfortunately with removing the p tag, it also remove a lot of plugins ability to function properly.

Ive shifted between a few solutions over the last year or two, and none of them is perfect, but the one giving me most joy at present is listed below:

function croma_remove_empty_p($content) {   
	$array = array (
		'

[' => '[', ']

' => ']', ']
' => ']', ']
' => ']' ); $content = strtr($content, $array); return $content; } add_filter('the_content', 'croma_remove_empty_p', 10);

Hey Net-Labs, you should not use above code because it affects 3rd party shortcodes as well.

Instead, use this: https://gist.github.com/bitfade/4555047

It’s TF approved and it only affects shortcodes you specify.

props to bitfade/pixelentity

||+920754|Net-Labs said-|| Wow, removing autop is a sure way to make a few enemies. Unfortunately with removing the p tag, it also remove a lot of plugins ability to function properly.

I totally agree.

I think you should see point 9 on WordPress Theme Submission Requirements: http://support.envato.com/index.php?/Knowledgebase/Article/View/472/85/wordpress-theme-submission-requirements

9. Modification of filters in wpautop is not allowed.
OriginalEXE said

Hey Net-Labs, you should not use above code because it affects 3rd party shortcodes as well.

Instead, use this: https://gist.github.com/bitfade/4555047

It’s TF approved and it only affects shortcodes you specify.

props to bitfade/pixelentity

Wow, this is the first solution that i see that have the idea of filtering for specific shortcodes, I’m keen to give it a try.

While the p’s is slowly driving be round the bend, i just do not want to do things that can break other stuff.

Thanks for the code