get_shortcode_tags_in_content

函数
get_shortcode_tags_in_content ( $content )
参数
  • (string) $content The content to check.
    Required:
返回值
  • (string[]) An array of registered shortcode names found in the content.
定义位置
相关方法
get_url_in_contentget_shortcode_atts_regexget_the_contentget_theme_starter_content_filter_do_shortcode_context
引入
6.3.2
弃用
-

返回在给定内容中找到的已注册短代码名称列表。

示例用法:

function get_shortcode_tags_in_content( $content ) {
	if ( false === strpos( $content, '[' ) ) {
		return array();
	}

	preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER );
	if ( empty( $matches ) ) {
		return array();
	}

	$tags = array();
	foreach ( $matches as $shortcode ) {
		$tags[] = $shortcode[2];

		if ( ! empty( $shortcode[5] ) ) {
			$deep_tags = get_shortcode_tags_in_content( $shortcode[5] );
			if ( ! empty( $deep_tags ) ) {
				$tags = array_merge( $tags, $deep_tags );
			}
		}
	}

	return $tags;
}

常见问题

FAQs
查看更多 >