strip_shortcodes

Remove all shortcode tags from the given content.

Description

(string) strip_shortcodes( (string) $content ); 

Returns (string)

Content without shortcode tags.

Parameters (1)

0. $content (string)
Content to remove shortcode tags.

Usage

  1. if ( !function_exists( 'strip_shortcodes' ) ) { 
  2. require_once ABSPATH . WPINC . '/shortcodes.php'; 
  3.  
  4. // Content to remove shortcode tags. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = strip_shortcodes($content); 
  9.  

Defined (1)

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

/wp-includes/shortcodes.php  
  1. function strip_shortcodes( $content ) { 
  2. global $shortcode_tags; 
  3.  
  4. if ( false === strpos( $content, '[' ) ) { 
  5. return $content; 
  6.  
  7. if (empty($shortcode_tags) || !is_array($shortcode_tags)) 
  8. return $content; 
  9.  
  10. // Find all registered tag names in $content. 
  11. preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); 
  12.  
  13. $tags_to_remove = array_keys( $shortcode_tags ); 
  14.  
  15. /** 
  16. * Filters the list of shortcode tags to remove from the content. 
  17. * @since 4.7.0 
  18. * @param array $tag_array Array of shortcode tags to remove. 
  19. * @param string $content Content shortcodes are being removed from. 
  20. */ 
  21. $tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content ); 
  22.  
  23. $tagnames = array_intersect( $tags_to_remove, $matches[1] ); 
  24.  
  25. if ( empty( $tagnames ) ) { 
  26. return $content; 
  27.  
  28. $content = do_shortcodes_in_html_tags( $content, true, $tagnames ); 
  29.  
  30. $pattern = get_shortcode_regex( $tagnames ); 
  31. $content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content ); 
  32.  
  33. // Always restore square braces so we don't break things like <!--[if IE ]> 
  34. $content = unescape_invalid_shortcodes( $content ); 
  35.  
  36. return $content;