Skip to content

Instantly share code, notes, and snippets.

@Mr2P
Created December 21, 2012 09:14
Show Gist options
  • Save Mr2P/4351664 to your computer and use it in GitHub Desktop.
Save Mr2P/4351664 to your computer and use it in GitHub Desktop.
<?php
// clean up shortcode
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 );
// example of cleaning of the shortcode
function test_shortcode($atts, $content) {
extract(shortcode_atts(array(
'id' => '284882215' // default
), $atts));
$content = parse_shortcode_content($content);
return $content;
}
add_shortcode('test','test_shortcode');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment