the_title_attribute()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
the_title_attribute( string|array $args = '' ): void|string
Описание
Работает как the_title() , за исключением того, что параметры могут передаваться строкой или массивом. Смотрите эту функцию, чтобы узнать, что можно переопределить в параметре $args .
Перед выводом из заголовка удаляются теги и он проходит через esc_attr() , прежде чем будет передан пользователю или выведен. По умолчанию, как и в the_title() , заголовок выводится.
Оригинал (английский)
Works like the_title() , except the parameters can be in a string or an array. See the function for what can be override in the $args parameter.
The title before it is displayed will have the tags stripped and esc_attr() before it is passed to the user or displayed. The default as with the_title() , is to display the title.
Параметры
$args
string|array
необязательный
= ''
Возвращаемое значение
void|string
Исходный код
wp-includes/post-template.php:81
function the_title_attribute( $args = '' ) {
$defaults = array(
'before' => '',
'after' => '',
'echo' => true,
'post' => get_post(),
);
$parsed_args = wp_parse_args( $args, $defaults );
$title = get_the_title( $parsed_args['post'] );
if ( strlen( $title ) === 0 ) {
return;
}
$title = $parsed_args['before'] . $title . $parsed_args['after'];
$title = esc_attr( strip_tags( $title ) );
if ( $parsed_args['echo'] ) {
echo $title;
} else {
return $title;
}
}
История изменений
| Версия | Описание |
|---|---|
| 2.3.0 | Introduced. |

