# Hide Leftover Shortcodes From Removed Plugins

> Hides shortcodes such as [old_slider id="3"] that show up as raw text after the plugin that handled them was removed.

- Type: PHP
- Runs: Frontend only
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: shortcodes, cleanup, plugins
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/hide-orphaned-shortcodes/

## Code

```php
add_filter( 'the_content', function ( $content ) {
    if ( false === strpos( $content, '[' ) ) {
        return $content;
    }

    $result = preg_replace_callback( '/\[(\/?)([a-zA-Z][\w\-]*)(\s[^\]]*)?\]/', function ( $m ) {
        if ( shortcode_exists( $m[2] ) ) {
            return $m[0];
        }

        $looks_like_shortcode = '/' === $m[1] || ! empty( $m[3] ) || preg_match( '/[_\-]/', $m[2] );

        return $looks_like_shortcode ? '' : $m[0];
    }, $content );

    return null === $result ? $content : $result;
}, 12 );
```

## Notes

To avoid removing normal bracketed text, only tags with attributes, a closing tag, or an underscore or hyphen in their name are hidden.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Hide Leftover Shortcodes From Removed Plugins" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
