wpseek.com
WordPress开发者和主题制作者的搜索引擎
has_shortcode › WordPress Function
Since3.6.0
已弃用n/a
› has_shortcode ( $content, $tag )
参数: (2) |
|
返回: |
|
定义在: |
|
文档: |
Determines whether the passed content contains the specified shortcode.
Related Functions: add_shortcode, do_shortcode, strip_shortcodes, apply_shortcodes, gallery_shortcode
源码
function has_shortcode( $content, $tag ) { if ( ! str_contains( $content, '[' ) ) { return false; } if ( shortcode_exists( $tag ) ) { preg_match_all( '/' . get_shortcode_regex() . '/', $content, $matches, PREG_SET_ORDER ); if ( empty( $matches ) ) { return false; } foreach ( $matches as $shortcode ) { if ( $tag === $shortcode[2] ) { return true; } elseif ( ! empty( $shortcode[5] ) && has_shortcode( $shortcode[5], $tag ) ) { return true; } } } return false; }