add_shortcode()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
add_shortcode( string $tag, callable $callback )
Описание
Следует позаботиться — с помощью префиксов или иными способами — о том, чтобы добавляемый тег шорткода был уникальным и не конфликтовал с другими, уже добавленными тегами шорткодов. В случае дублирования тега приоритет получит тег, загруженный последним.
Оригинал (английский)
Care should be taken through prefixing or other means to ensure that the shortcode tag being added is unique and will not conflict with other, already-added shortcode tags. In the event of a duplicated tag, the tag loaded last will take precedence.
Параметры
$tag
string
обязательный
$callback
callable
обязательный
Исходный код
wp-includes/shortcodes.php:63
function add_shortcode( $tag, $callback ) {
global $shortcode_tags;
if ( '' === trim( $tag ) ) {
_doing_it_wrong(
__FUNCTION__,
__( 'Invalid shortcode name: Empty name given.' ),
'4.4.0'
);
return;
}
if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20=]@', $tag ) ) {
_doing_it_wrong(
__FUNCTION__,
sprintf(
/* translators: 1: Shortcode name, 2: Space-separated list of reserved characters. */
__( 'Invalid shortcode name: %1$s. Do not use spaces or reserved characters: %2$s' ),
$tag,
'& / < > [ ] ='
),
'4.4.0'
);
return;
}
$shortcode_tags[ $tag ] = $callback;
}
История изменений
| Версия | Описание |
|---|---|
| 2.5.0 | Introduced. |

