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

---

# shortcode_unautop( string $text ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#changelog)

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

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/shortcode_unautop/?output_format=md#description)󠁿

Ensures that shortcodes are not wrapped in `<p>...</p>`.

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

 `$text`stringrequired

The content.

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

 string The filtered content.

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

    ```php
    function shortcode_unautop( $text ) {
    	global $shortcode_tags;

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

    	$tagregexp = implode( '|', array_map( 'preg_quote', array_keys( $shortcode_tags ) ) );
    	$spaces    = wp_spaces_regexp();

    	// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound,Universal.WhiteSpace.PrecisionAlignment.Found -- don't remove regex indentation
    	$pattern =
    		'/'
    		. '<p>'                              // Opening paragraph.
    		. '(?:' . $spaces . ')*+'            // Optional leading whitespace.
    		. '('                                // 1: The shortcode.
    		.     '\\['                          // Opening bracket.
    		.     "($tagregexp)"                 // 2: Shortcode name.
    		.     '(?![\\w-])'                   // Not followed by word character or hyphen.
    											 // Unroll the loop: Inside the opening shortcode tag.
    		.     '[^\\]\\/]*'                   // Not a closing bracket or forward slash.
    		.     '(?:'
    		.         '\\/(?!\\])'               // A forward slash not followed by a closing bracket.
    		.         '[^\\]\\/]*'               // Not a closing bracket or forward slash.
    		.     ')*?'
    		.     '(?:'
    		.         '\\/\\]'                   // Self closing tag and closing bracket.
    		.     '|'
    		.         '\\]'                      // Closing bracket.
    		.         '(?:'                      // Unroll the loop: Optionally, anything between the opening and closing shortcode tags.
    		.             '[^\\[]*+'             // Not an opening bracket.
    		.             '(?:'
    		.                 '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag.
    		.                 '[^\\[]*+'         // Not an opening bracket.
    		.             ')*+'
    		.             '\\[\\/\\2\\]'         // Closing shortcode tag.
    		.         ')?'
    		.     ')'
    		. ')'
    		. '(?:' . $spaces . ')*+'            // Optional trailing whitespace.
    		. '<\\/p>'                           // Closing paragraph.
    		. '/';
    	// phpcs:enable

    	return preg_replace( $pattern, '$1', $text );
    }
    ```

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

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

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

Returns the regexp for common whitespace characters.

  |

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

Applies standard content filters similar to the ‘the_content’ filter.

  | 
| [get_the_block_template_html()](https://developer.wordpress.org/reference/functions/get_the_block_template_html/)`wp-includes/block-template.php` |

Returns the markup for the current template.

  | 
| [WP_Widget_Text::widget()](https://developer.wordpress.org/reference/classes/wp_widget_text/widget/)`wp-includes/widgets/class-wp-widget-text.php` |

Outputs the content for the current Text widget instance.

  |

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

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

## User Contributed Notes

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