WordPress输出当前文章标题标签:the_title_attribute

WordPress模板标签the_title_attribute用于输出当前文章的标题,和the_title()相似,但the_title_attribute()去除了标题中的HTML标签。

the_title_attribute( string|array $args = '' )

函数参数

$args

数组或字符串

the_title_attribute()函数$args参数默认的值如下:

$args = array( 
	'before'	=> '',
	'after'		=>  '',
	'echo'		=> true,
	'post'		=> get_post()
);

the_title_attribute()函数$args参数可用的值如下:

before

字符串值,默认为空

在标题前添加内容

after

字符串值,默认为空

在标题后添加内容

echo

布尔值,默认值:true

是否输出标题,如果为false,只返回结果而不输出。

post

整数型或对象,默认值:get_post()函数返回的值

指定一个文章ID或对象,用来输出特定文章的标题。

函数使用示例

这个示例在<a>标签的title属性中输出了文章标题,并在标题前输出:Permalink to

<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute( array( 'before' => 'Permalink to: ', 'after' => '' ) ); ?>"><?php the_title(); ?></a>

扩展阅读

the_title_attribute()函数位于:wp-includes/post-template.php

相关函数:

阿里云