the_title_attribute()
the_title_attribute( string|array $args = ” ) 检索或显示时清除当…
the_title_attribute( string|array $args = ” )
检索或显示时清除当前标题。
Sanitize the current title when retrieving or displaying.
检索或显示时清除当前标题。
Sanitize the current title when retrieving or displaying.
目录锚点:#说明#源码#笔记
说明(Description)
其工作方式与_title()类似,但参数可以是字符串或数组。有关$args参数中可以重写的内容,请参阅函数。显示之前的标题将删除标记,并在传递给用户或显示之前使用esc_attr()。默认情况下,与_title()一样,显示标题。
源码(Source)
/**
* Sanitize the current title when retrieving or displaying.
*
* Works like {@link 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 {@link
* esc_attr()} before it is passed to the user or displayed. The default
* as with {@link the_title()}, is to display the title.
*
* @since 2.3.0
*
* @param 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.
* }
* @return string|void String when echo is false.
*/
function the_title_attribute( $args = '' ) {
$defaults = array( 'before' => '', 'after' => '', 'echo' => true, 'post' => get_post() );
$r = wp_parse_args( $args, $defaults );
$title = get_the_title( $r['post'] );
if ( strlen( $title ) == 0 ) {
return;
}
$title = $r['before'] . $title . $r['after'];
$title = esc_attr( strip_tags( $title ) );
if ( $r['echo'] ) {
echo $title;
} else {
return $title;
}
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.3.0 | wp-includes/post-template.php | 13 | 5 |
笔记(Notes)
带文本参数的PHP
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!