Wordpress adds extra paragraph tag


#1

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..


#2

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


#3

Add this in your theme’s functions.php file

remove_filter(‘the_content’, ‘wpautop’);

Hopefully this will work. :smiley:


#4
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:


#5
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)


#6

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.


#7

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]

#8
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.


#9

This worked for me as well! Thanks a million!


#10

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

#11

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


#12
||+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.

#13
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