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.
p tags in shortcodes?
ewizz said
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.
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]
winterbits said
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 
- Author had a Free File of the Month
- Bought between 1 and 9 items
- Exclusive Author
- Has been a member for 3-4 years
- Referred between 200 and 499 users
- Sold between 50 000 and 100 000 dollars
elemis said
winterbits saidThanks you for your support. However surrounding shortcodes with another shortcode probably will be too complex for some users
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]
![]()
I don’t think so. I use the same technique and so far no complaints from clients.
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.
wpCanyonThemes said
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 itSo the user doesn’t have to do it himself.
man! where have you been? you didn’t posted anything on forum for whole day !! 
Noone needed my help whole day 
And finishing up the theme so don’t have much time for the forum 
@winterbits – Any progress?
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;
}
