Hi, everyone! I need to remove wpautop from shortcodes. I use a code by OrganicBeeMedia I have found here:
//Clean Up WordPress Shortcode Formatting - important for nested shortcodes
//adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {
/* Parse nested shortcodes and add formatting. */
$content = trim( do_shortcode( shortcode_unautop( $content ) ) );
/* Remove '' from the start of the string. */
if ( substr( $content, 0, 4 ) == '' )
$content = substr( $content, 4 );
/* Remove '' from the end of the string. */
if ( substr( $content, -3, 3 ) == '' )
$content = substr( $content, 0, -3 );
/* Remove any instances of ''. */
$content = str_replace( array( '<p></p>' ), '', $content );
$content = str_replace( array( '<p> </p>' ), '', $content );
return $content;
}
//move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
Seems it’s work fine but WP still converts my quotes
'to #8216
Any help please?
I use this in my WPTS that I use in my themes:
/*-----------------------------------------------------------------------------------*/
/* WP Auto Formatting Fix w/Raw shortocde
/*-----------------------------------------------------------------------------------*/
if( ! function_exists( 'wpts_content_formatter' ) ) {
function wpts_content_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 .= shortcode_unautop( wptexturize( wpautop( $piece ) ) );
}
}
return $new_content;
}
}
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_content', 'wptexturize' );
remove_filter( 'the_content', 'shortcode_unautop' );
add_filter( 'the_content', 'wpts_content_formatter', 99 );
With this one, you need wrap the content that will have the wpautop removed with raw
Hope it helps ;D
Cheers, Rafael Angeline
RDever said
I use this in my WPTS that I use in my themes:/*-----------------------------------------------------------------------------------*/ /* WP Auto Formatting Fix w/Raw shortocde /*-----------------------------------------------------------------------------------*/ if( ! function_exists( 'wpts_content_formatter' ) ) { function wpts_content_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 .= shortcode_unautop( wptexturize( wpautop( $piece ) ) ); } } return $new_content; } } remove_filter( 'the_content', 'wpautop' ); remove_filter( 'the_content', 'wptexturize' ); remove_filter( 'the_content', 'shortcode_unautop' ); add_filter( 'the_content', 'wpts_content_formatter', 99 );With this one, you need wrap the content that will have the wpautop removed with raw
Hope it helps ;D
Cheers, Rafael Angeline
thats really really really really really bad practice…..
RDever, thanks for your reply, ok, now I have this:
$output .= trim( do_shortcode( shortcode_unautop( $content ) ) );
Could you be bore specific in what I need to wrap a $content? By the way I have disabled converting with this one:
remove_filter('the_content', 'wptexturize');
What do u think? it’s a fine solution?
you want to filter your shortcodes that dont need to be texturized through a filter…
add_filter( 'no_texturize_shortcodes', 'your_prefix_no_texturize' );
function your_prefix_no_texturize( $fix_stuff ) {
$fix_stuff[] = array('make' , 'this', 'a', 'array');
return $fix_stuff;
}
see wp-includes/formating.php line 60
ps that original code is NOT mine
NOTE : i haven’t tested this and typed it in here so there may be errors
OrganicBeeMedia, whta about code that I use, hope it’s ok to use it?
//Clean Up WordPress Shortcode Formatting - important for nested shortcodes
//adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {
/* Parse nested shortcodes and add formatting. */
$content = trim( do_shortcode( shortcode_unautop( $content ) ) );
/* Remove '' from the start of the string. */
if ( substr( $content, 0, 4 ) == '' )
$content = substr( $content, 4 );
/* Remove '' from the end of the string. */
if ( substr( $content, -3, 3 ) == '' )
$content = substr( $content, 0, -3 );
/* Remove any instances of ''. */
$content = str_replace( array( '<p></p>' ), '', $content );
$content = str_replace( array( '<p> </p>' ), '', $content );
return $content;
}
//move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
remove_filter('the_content', 'wptexturize');
Pixelous said
OrganicBeeMedia, whta about code that I use, hope it’s ok to use it?
yes see my last post..
the problem with the other code posted it forces users to wrap there post in a shortcode just to make a shortcode work which is extremely bad UX and it can cause a bunch of other problems
This is what I use:
function my_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 back, to not strip WordPress core functionality
add_filter('the_content', 'my_formatter', 99);digitalimpact said
This is what I use:function my_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 back, to not strip WordPress core functionality add_filter('the_content', 'my_formatter', 99);
cough bad practice…

