функция
since 3.6.0
has_shortcode()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
has_shortcode( string $content, string $tag ): bool
Описание
Определяет, содержит ли переданное содержимое указанный шорткод.
Параметры
$content
string
обязательный
Содержимое для поиска шорткодов.
$tag
string
обязательный
Тег шорткода для проверки.
Возвращаемое значение
bool
Исходный код
wp-includes/shortcodes.php:149
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;
}
История изменений
| Версия | Описание |
|---|---|
| 3.6.0 | Introduced. |

