111 posts
  • Featured Author
  • Elite Author
  • Top Monthly Author
  • Featured Item
+8 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
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
ewizz
says

p tags in shortcodes?

111 posts
  • Featured Author
  • Elite Author
  • Top Monthly Author
  • Featured Item
+8 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
  • 7 Years of Membership
  • Winner
  • Featured Author
  • Featured Item
+7 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
  • Featured Author
  • Elite Author
  • Top Monthly Author
  • Featured Item
+8 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
  • Weekly Top Seller
  • Elite Author
  • Author Level 7
  • 6 Years of Membership
+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
  • 6 Years of Membership
  • Affiliate Level 2
  • Collector Level 2
  • Exclusive Author
+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
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
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
  • 6 Years of Membership
  • Affiliate Level 2
  • Collector Level 2
  • Exclusive Author
+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
  • Affiliate Level 2
  • Author Level 5
  • Beta Tester
  • Collector Level 2
+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