Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Clean up the hairy formatting results of do_shortcode().
- *
- * Removes any opening and closing <br /> tags,
- * and removes the break tags from the middle of
- * </div><br /><div and </p><br /><p
- *
- *
- * @since 0.1.0
- *
- * @param string $content The content.
- *
- * @return string The do_shortcode-ed content.
- */
- function do_shortcode_and_clean( $content ) {
- if ( $content ) {
- // For some reason, WP really wants to insert a break tag at the beginning.
- $content = preg_replace( '/^<br \/>([\s]{1,})?/', '', $content );
- $content = do_shortcode( $content );
- // More annoying WP break tags.
- $content = preg_replace_callback( '/(<\/(div|p)><br([\s]{1,})\/>([\s]{1,})?<(div|p))/', function( $matches ) {
- return '</' . $matches[2] . '><' . $matches[5];
- }, $content );
- // Remove trailing break tag.
- $content = preg_replace( '/([\s]{1,})?<br \/>$/', '', $content );
- }
- return $content;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement