111 posts
  • Became a Top 20 Author of the Month
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 100+ items on Envato Market
+6 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 5 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
ewizz
says

p tags in shortcodes?

111 posts
  • Became a Top 20 Author of the Month
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 100+ items on Envato Market
+6 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.

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
brumale
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
  • Became a Top 20 Author of the Month
  • Has referred 1000+ members
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has collected 100+ items on Envato Market
+6 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
+3 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 5 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;
}
by
by
by
by
by
by