111 posts
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 50+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
elemis says

Hello guys,

Is there a way of only removing p tags that are generated inside shortcodes? We don’t want to use wpautop filter. The clients should still be able to format their text by line breaks. But when this is being applied in shortcodes it messes up shortcode output.

We reeeeeally reaaaally need to solve this :)

Any help would be appreciated. Thanks in advance.

238 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
ewizz says

p tags in shortcodes?

111 posts
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 50+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
elemis says

p tags in shortcodes?

When writing posts with shortcodes

 [divtag]
 abc
 [/divtag]

ends up as

< div >
<p>abc</p>
<p>< / div ></p>

We want to get rid of this automatically generated p tags.

StefanoGiliberti
StefanoGiliberti Recent Posts Threads Started
32 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+6 more
StefanoGiliberti says
function formatter($content) {
    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($pieces as $piece) {
        if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
        } else {
            $new_content .= wptexturize(wpautop($piece));
        }
    }
    return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'formatter', 99);

[raw]Content without Paragraphs[/raw]

111 posts
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 50+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+5 more
elemis says

function formatter($content) {
    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($pieces as $piece) {
        if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
        } else {
            $new_content .= wptexturize(wpautop($piece));
        }
    }
    return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'formatter', 99);

[raw]Content without Paragraphs[/raw]

Thanks you for your support. However surrounding shortcodes with another shortcode probably will be too complex for some users :(

562 posts You Reap What You Saw
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been part of the Envato Community for over 5 years
  • Contributed a free file of the month
+4 more
Bluz says


function formatter($content) {
    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
    foreach ($pieces as $piece) {
        if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
        } else {
            $new_content .= wptexturize(wpautop($piece));
        }
    }
    return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'formatter', 99);

[raw]Content without Paragraphs[/raw]

Thanks you for your support. However surrounding shortcodes with another shortcode probably will be too complex for some users :(

I don’t think so. I use the same technique and so far no complaints from clients.

1383 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

Or in the shortcodes you want to do this for, just before you return the output put [raw] before the output string and [/raw] after it. Then return do_shortcode($output) and that’s it :)

So the user doesn’t have to do it himself.

238 posts
  • Has been part of the Envato Community for over 4 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
ewizz says

Or in the shortcodes you want to do this for, just before you return the output put [raw] before the output string and [/raw] after it. Then return do_shortcode($output) and that’s it :) So the user doesn’t have to do it himself.

man! where have you been? you didn’t posted anything on forum for whole day !! :D

1383 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 10+ members
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
wpCanyonThemes says

Noone needed my help whole day :)

And finishing up the theme so don’t have much time for the forum :)

@winterbits – Any progress?

709 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

Put this in functions.php.

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

Example/Usage:

add_shortcode( 'blockquote', 'blockquote_shortcode' );
function blockquote_shortcode( $attr, $content = null ) {
    $return .= '<blockquote>';
    $return .= remove_wpautop($content);
    $return .= '</blockquote>';
    return $return;
}

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by