Title: do_shortcode_tag
Published: April 25, 2014
Last modified: April 28, 2025

---

# do_shortcode_tag( array $m ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#changelog)

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

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Regular Expression callable for [do_shortcode()](https://developer.wordpress.org/reference/functions/do_shortcode/)
for calling shortcode hook.

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

### 󠀁[See also](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#see-also)󠁿

 * [get_shortcode_regex()](https://developer.wordpress.org/reference/functions/get_shortcode_regex/):
   for details of the match array contents.

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

 `$m`arrayrequired

Regular expression match array.

 * `0` string
 * Entire matched shortcode text.
 * `1` string
 * Optional second opening bracket for escaping shortcodes.
 * `2` string
 * Shortcode name.
 * `3` string
 * Shortcode arguments list.
 * `4` string
 * Optional self closing slash.
 * `5` string
 * Content of a shortcode when it wraps some content.
 * `6` string
 * Optional second closing bracket for escaping shortcodes.

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

 string Shortcode output.

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

    ```php
    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 = isset( $m[5] ) ? $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 );
    }
    ```

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

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

 [apply_filters( ‘do_shortcode_tag’, string $output, string $tag, array $attr, array $m )](https://developer.wordpress.org/reference/hooks/do_shortcode_tag/)

Filters the output created by a shortcode callback.

 [apply_filters( ‘pre_do_shortcode_tag’, false|string $output, string $tag, array $attr, array $m )](https://developer.wordpress.org/reference/hooks/pre_do_shortcode_tag/)

Filters whether to call a shortcode callback.

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

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

Retrieves all attributes from the shortcodes tag.

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

Retrieves the translation of $text.

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

Marks something as being incorrectly called.

  | 
| [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 2 more](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/do_shortcode_tag/?output_format=md#)

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

Retrieves galleries from the passed post’s content.

  |

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

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

## User Contributed Notes

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