Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Clean up the hairy formatting results of do_shortcode().
  5. *
  6. * Removes any opening and closing <br /> tags,
  7. * and removes the break tags from the middle of
  8. * </div><br /><div and </p><br /><p
  9. *
  10. *
  11. * @since 0.1.0
  12. *
  13. * @param string $content The content.
  14. *
  15. * @return string The do_shortcode-ed content.
  16. */
  17. function do_shortcode_and_clean( $content ) {
  18. if ( $content ) {
  19.  
  20. // For some reason, WP really wants to insert a break tag at the beginning.
  21. $content = preg_replace( '/^<br \/>([\s]{1,})?/', '', $content );
  22.  
  23. $content = do_shortcode( $content );
  24. // More annoying WP break tags.
  25. $content = preg_replace_callback( '/(<\/(div|p)><br([\s]{1,})\/>([\s]{1,})?<(div|p))/', function( $matches ) {
  26. return '</' . $matches[2] . '><' . $matches[5];
  27. }, $content );
  28.  
  29. // Remove trailing break tag.
  30. $content = preg_replace( '/([\s]{1,})?<br \/>$/', '', $content );
  31. }
  32.  
  33. return $content;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement