the_title_attribute
函数
the_title_attribute ( $args = '' )
- 参数
-
-
(string|array)
$args
{ Title attribute arguments. Optional. @type string $before Markup to prepend to the title. Default empty. @type string $after Markup to append to the title. Default empty. @type bool $echo Whether to echo or return the title. Default true for echo. @type WP_Post $post Current post object to retrieve the title for. }- Required: 否
- Default: (empty)
-
(string|array)
- 返回值
-
- (void|string) Void if ‘echo’ argument is true, the title attribute if ‘echo’ is false.
- 定义位置
-
-
wp-includes/post-template.php
, line 80
-
wp-includes/post-template.php
- 引入
- 2.3.0
- 弃用
- –
Sanitizes the current title when retrieving or displaying.
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.
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;
}
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


