shortcode_unautop

Don't auto-p wrap shortcodes that stand alone.

Description

(string) shortcode_unautop( (string) $pee ); 

Ensures that shortcodes are not wrapped in

...

..

Returns (string)

The filtered content.

Parameters (1)

0. $pee (string)
The content.

Usage

  1. if ( !function_exists( 'shortcode_unautop' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // The content. 
  5. $pee = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = shortcode_unautop($pee); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/formatting.php  
  1. function shortcode_unautop( $pee ) { 
  2. global $shortcode_tags; 
  3.  
  4. if ( empty( $shortcode_tags ) || !is_array( $shortcode_tags ) ) { 
  5. return $pee; 
  6.  
  7. $tagregexp = join( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) ); 
  8. $spaces = wp_spaces_regexp(); 
  9.  
  10. $pattern = 
  11. '/' 
  12. . '<p>' // Opening paragraph 
  13. . '(?:' . $spaces . ')*+' // Optional leading whitespace 
  14. . '(' // 1: The shortcode 
  15. . '\\[' // Opening bracket 
  16. . "($tagregexp)" // 2: Shortcode name 
  17. . '(?![\\w-])' // Not followed by word character or hyphen 
  18. // Unroll the loop: Inside the opening shortcode tag 
  19. . '[^\\]\\/]*' // Not a closing bracket or forward slash 
  20. . '(?:' 
  21. . '\\/(?!\\])' // A forward slash not followed by a closing bracket 
  22. . '[^\\]\\/]*' // Not a closing bracket or forward slash 
  23. . ')*?' 
  24. . '(?:' 
  25. . '\\/\\]' // Self closing tag and closing bracket 
  26. . '|' 
  27. . '\\]' // Closing bracket 
  28. . '(?:' // Unroll the loop: Optionally, anything between the opening and closing shortcode tags 
  29. . '[^\\[]*+' // Not an opening bracket 
  30. . '(?:' 
  31. . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag 
  32. . '[^\\[]*+' // Not an opening bracket 
  33. . ')*+' 
  34. . '\\[\\/\\2\\]' // Closing shortcode tag 
  35. . ')?' 
  36. . ')' 
  37. . ')' 
  38. . '(?:' . $spaces . ')*+' // optional trailing whitespace 
  39. . '<\\/p>' // closing paragraph 
  40. . '/'; 
  41.  
  42. return preg_replace( $pattern, '$1', $pee );