Title: strip_shortcodes
Published: April 25, 2014
Last modified: August 20, 2026

---

# strip_shortcodes( string $content ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#wp--skip-link--target)

Removes all shortcode tags from the given content.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#parameters)󠁿

 `$content`stringrequired

Content to remove shortcode tags.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#return)󠁿

 string Content without shortcode tags.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#source)󠁿

    ```php
    function strip_shortcodes( $content ) {
    	global $shortcode_tags;

    	if ( ! str_contains( $content, '[' ) ) {
    		return $content;
    	}

    	if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) {
    		return $content;
    	}

    	// Find all registered tag names in $content.
    	preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches );

    	$tags_to_remove = array_keys( $shortcode_tags );

    	/**
    	 * Filters the list of shortcode tags to remove from the content.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param array  $tags_to_remove Array of shortcode tags to remove.
    	 * @param string $content        Content shortcodes are being removed from.
    	 */
    	$tags_to_remove = apply_filters( 'strip_shortcodes_tagnames', $tags_to_remove, $content );

    	$tagnames = array_intersect( $tags_to_remove, $matches[1] );

    	if ( empty( $tagnames ) ) {
    		return $content;
    	}

    	$content = do_shortcodes_in_html_tags( $content, true, $tagnames );

    	$pattern = get_shortcode_regex( $tagnames );
    	$content = preg_replace_callback( "/$pattern/", 'strip_shortcode_tag', $content );

    	// Always restore square braces so we don't break things like <!--[if IE ]>.
    	$content = unescape_invalid_shortcodes( $content );

    	return $content;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/shortcodes.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/shortcodes.php#L706)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/shortcodes.php#L706-L747)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#hooks)󠁿

 [apply_filters( ‘strip_shortcodes_tagnames’, array $tags_to_remove, string $content )](https://developer.wordpress.org/reference/hooks/strip_shortcodes_tagnames/)

Filters the list of shortcode tags to remove from the content.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#related)󠁿

| Uses | Description | 
| [do_shortcodes_in_html_tags()](https://developer.wordpress.org/reference/functions/do_shortcodes_in_html_tags/)`wp-includes/shortcodes.php` |

Searches only inside HTML elements for shortcodes and process them.

  | 
| [unescape_invalid_shortcodes()](https://developer.wordpress.org/reference/functions/unescape_invalid_shortcodes/)`wp-includes/shortcodes.php` |

Removes placeholders added by [do_shortcodes_in_html_tags()](https://developer.wordpress.org/reference/functions/do_shortcodes_in_html_tags/) .

  | 
| [get_shortcode_regex()](https://developer.wordpress.org/reference/functions/get_shortcode_regex/)`wp-includes/shortcodes.php` |

Retrieves the shortcode regular expression for searching.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#)

| Used by | Description | 
| [wp_trim_excerpt()](https://developer.wordpress.org/reference/functions/wp_trim_excerpt/)`wp-includes/formatting.php` |

Generates an excerpt from the content, if needed.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#comment-content-3071)
 2.    [Vitalii Kiiko](https://profiles.wordpress.org/mrpsiho/)  [  8 years ago  ](https://developer.wordpress.org/reference/functions/strip_shortcodes/#comment-3071)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%23comment-3071)
     Vote results for this note: 6[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%23comment-3071)
 4.  It is worth to note that this function removes only those shortcodes which are
     registered at the moment of the processing of this function. If there are any “
     leftovers” shortcodes, like those which were added by some plugin but that plugin
     is not active anymore, this function WILL NOT strip them. It is possible to check
     which shortcodes may and will be stripped with the help of this filter `strip_shortcodes_tagnames`
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%3Freplytocom%3D3071%23feedback-editor-3071)
 6.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/strip_shortcodes/?output_format=md#comment-content-671)
 7.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/strip_shortcodes/#comment-671)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%23comment-671)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%23comment-671)
 9.  **Strip shortcodes on home page but not on single or archive pages**
      When viewing
     posts ‘home’ page, strip all shortcodes, but on other pages, such as _single.php_,
     do not strip the shortcodes.
 10.     ```php
         /**
          * Remove shortcodes if we are on the home page
          *
          * @param string $content Post content.
          * @return string (Maybe) modified post content.
          */
         function wpdocs_remove_shortcode_from_index( $content ) {
         	if ( is_home() ) {
         		$content = strip_shortcodes( $content );
         	}
         	return $content;
         }
         add_filter( 'the_content', 'wpdocs_remove_shortcode_from_index' );
         ```
     
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F%3Freplytocom%3D671%23feedback-editor-671)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fstrip_shortcodes%2F)
before being able to contribute a note or feedback.