shortcode_unautop()
Don't auto-p wrap shortcodes that stand alone
Ensures that shortcodes are not wrapped in <p>...</p>.
1 time — 0.000067 sec (very fast) | 50000 times — 0.67 sec (very fast)
No Hooks.
Return
String
. The filtered content.
Usage
shortcode_unautop( $text );
- $text(string) (required)
- The content.
Examples
#1 Demo of work
Suppose we have the shortcode short
registered. Then:
$str = ' <p>[short id="54"]</p> Text [short id="54"] Text <p> [short id="54"] </p> Text <p>[short id="54"] text</p> Shortcode with content <p>[short align="aligncenter" width="495"]any text inside[/short]</p> '; echo shortcode_unautop( $str ); /* We get: [short id="54"] Text [short id="54"] Text [short id="54"] Text <p>[short id="54"] text</p> Text [short align="aligncenter" width="495"]any text inside[/short] */
#2 Which regular expression is used
An example of what regular expression results from the function (depends on the shortcodes that are currently registered) (WP version 4.4):
(?:[\r\n\t ]|\xC2\xA0| )*+(\[(embed|wp_caption|caption|gallery|playlist|audio|video|democracy|democracy_archives|download)(?![\w-])[^\]\/]*(?:\/(?!\])[^\]\/]*)*?(?:\/\]|\](?:[^\[]*+(?:\[(?!\/\])[^\[]*+)*+\[\/\])?))(?:[\r\n\t ]|\xC2\xA0| )*+<\/p>
Notes
- Global. Array. $shortcode_tags
Changelog
Since 2.9.0 | Introduced. |