97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says

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]
<h4>Title</h4>
<p>Lorem ipsum..</p>
[/box]
Faulty Browser:
<div class="box">
<p></p>
<h4>Title</h4>
<p>Lorem ipsum..</p>
</div>
1950 posts Do the Needful
  • Has been a member for 4-5 years
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • United States
  • Has attended an Envato Live event
  • Author had a Free File of the Month
  • Envato Studio (Microlancer) Beta Tester
  • Contributed a Blog Post
  • Beta Tester
+6 more
JamiGibbs says

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

409 posts
  • Exclusive Author
  • Has been a member for 4-5 years
  • India
Dhruv says

Add this in your theme’s functions.php file

remove_filter('the_content', 'wpautop');

Hopefully this will work. :D

97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says
Add this in your theme’s functions.php file remove_filter('the_content', 'wpautop'); Hopefully this will work. :D

This totally worked! Many thanks! :)

707 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
ChillThemes says
function remove_wpautop( $content ) { 
    $content = do_shortcode( shortcode_unautop( $content ) ); 
    $content = preg_replace( '#^<\/p>|^<br \/>|<p>$#', '', $content );
    return $content;
}
</p>

You’d use it like this:

remove_wpautop($content)
438 posts
  • Exclusive Author
  • Has been a member for 3-4 years
  • United States
christopherjon says

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.

1028 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Author had a File in an Envato Bundle
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • Referred between 500 and 999 users
+1 more
ThemeBlvd says

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]
<h4>Title</h4>
<p>Lorem ipsum..</p>
[/box]

[box]
<h4>Title</h4>
<p>Lorem ipsum..</p>
[/box]

[box]
<h4>Title</h4>
<p>Lorem ipsum..</p>
[/box]

[/raw]
97 posts
  • Bought between 10 and 49 items
  • Elite Author
  • Exclusive Author
  • Finland
  • Has been a member for 5-6 years
  • Referred between 100 and 199 users
  • Sold between 250 000 and 1 000 000 dollars
Smuliii says
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.

1 post
  • Bought between 10 and 49 items
  • Has been a member for 1-2 years
swizzmagik says

This worked for me as well! Thanks a million!

90 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 200 and 499 users
  • South Africa
Net-Labs says

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 (
        '<p>[' => '[', 
        ']</p>' => ']', 
        ']<br />' => ']',
        ']<br />' => ']'
    );
    $content = strtr($content, $array);
        return $content;
}
add_filter('the_content', 'croma_remove_empty_p', 10);
by
by
by
by
by
by