do_shortcode_tag( array $m ): string
- Since
- 2.5.0
- Source
wp-includes/shortcodes.php:392
Compatibility
- WordPress
- since 2.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$marray- Regular expression match array.
$0stringEntire matched shortcode text.$1stringOptional second opening bracket for escaping shortcodes.$2stringShortcode name.$3stringShortcode arguments list.$4stringOptional self closing slash.$5stringContent of a shortcode when it wraps some content.$6stringOptional second closing bracket for escaping shortcodes.
Return value
string- Shortcode output.
Performance profile
How much work a call to do_shortcode_tag() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 12–52
- Plugin surface
- 2 hooks
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 71.
Third-party callbacks on 'pre_do_shortcode_tag', 'do_shortcode_tag' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost do_shortcode_tag() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12 | none |
is_callable() && $return !== false | 28–31 | shortcode_parse_atts(), is_callable(), apply_filters() |
!is_callable() | 31–34 | shortcode_parse_atts(), is_callable(), __(), sprintf(), _doing_it_wrong() |
is_callable() && $return === false | 48–52 | shortcode_parse_atts(), is_callable(), apply_filters(), call_user_func(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 71 | 12–52 | 5 | |
| 8.5 | 71 | 12–52 | 5 | |
| 8.4 | 71 | 12–52 | 5 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 74 | 15–52 | 5 | |
| 8.2 | 74 | 15–52 | 5 | |
| 8.1 | 74 | 15–52 | 5 | |
| 7.4 | 74 | 15–52 | 5 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while do_shortcode_tag() runs, in this order:
- apply_filters( pre_do_shortcode_tag )filterline 427 (+35 into the body)
Filters whether to call a shortcode callback.
- apply_filters( do_shortcode_tag )filterline 447 (+55 into the body)
Filters the output created by a shortcode callback.
Uses · 4
- shortcode_parse_atts()Retrieves all attributes from the shortcodes tag.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- get_post_galleries()Retrieves galleries from the passed post's content.
Source code
function do_shortcode_tag( $m ) { global $shortcode_tags; // Allow [[foo]] syntax for escaping a tag. if ( '[' === $m[1] && ']' === $m[6] ) { return substr( $m[0], 1, -1 ); } $tag = $m[2]; $attr = shortcode_parse_atts( $m[3] ); if ( ! is_callable( $shortcode_tags[ $tag ] ) ) { _doing_it_wrong( __FUNCTION__, /* translators: %s: Shortcode tag. */ sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ), '4.3.0' ); return $m[0]; } /** * Filters whether to call a shortcode callback. * * Returning a non-false value from filter will short-circuit the * shortcode generation process, returning that value instead. * * @since 4.7.0 * @since 6.5.0 The `$attr` parameter is always an array. * * @param false|string $output Short-circuit return value. Either false or the value to replace the shortcode with. * @param string $tag Shortcode name. * @param array $attr Shortcode attributes array, can be empty if the original arguments string cannot be parsed. * @param array $m Regular expression match array. */ $return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m ); if ( false !== $return ) { return $return; } $content = $m[5] ?? null; $output = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6]; /** * Filters the output created by a shortcode callback. * * @since 4.7.0 * @since 6.5.0 The `$attr` parameter is always an array. * * @param string $output Shortcode output. * @param string $tag Shortcode name. * @param array $attr Shortcode attributes array, can be empty if the original arguments string cannot be parsed. * @param array $m Regular expression match array. */ return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m );}Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/shortcodes.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.