has_shortcode()
has_shortcode( string $content, string $tag ) 传递的内容是否包含…
has_shortcode( string $content, string $tag )
传递的内容是否包含指定的快捷方式
Whether the passed content contains the specified shortcode
传递的内容是否包含指定的快捷方式
Whether the passed content contains the specified shortcode
目录锚点:#参数#返回#源码#笔记
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $content | (string) | 必需 | 搜索快捷方式的内容。 |
| $tag | (string) | 必需 | 要检查的快捷方式标记。 |
返回(Return)
(bool)传递的内容是否包含给定的快捷方式。
源码(Source)
function has_shortcode( $content, $tag ) {
if ( false === strpos( $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;
}
| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 3.6.0 | wp-includes/shortcodes.php:140 | 3 | 3 |
笔记(Notes)
当某个post使用某个shortcode时,将某个脚本排队。
简单的例子
$content = 'This is some text, (perhaps pulled via $post->post_content). It has a shortcode.';
if ( has_shortcode( $content, 'gallery' ) ) {
// The content has a short code, so this check returned true.
}
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
还没有任何评论,赶紧来占个楼吧!