admin管理员组文章数量:1387348
Using this code:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => the_title(),
'title' => the_title()
));
}
?>
However, alt and title are being output as text on website instead of enclosed tags. What should the syntax be instead?
Using this code:
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => the_title(),
'title' => the_title()
));
}
?>
However, alt and title are being output as text on website instead of enclosed tags. What should the syntax be instead?
Share Improve this question edited Feb 24, 2018 at 10:47 fuxia♦ 107k39 gold badges255 silver badges459 bronze badges asked Feb 23, 2018 at 16:44 JoaMikaJoaMika 6986 gold badges27 silver badges58 bronze badges 01 Answer
Reset to default 2Try using get_the_title
instead of the_title
- from the Function Reference:
the_title
- Display or retrieve the current post title with optional markup.get_the_title
- Retrieve post title.
You might notice that the_title
says "Display or retrieve" - and it's true, you can pass false
to the third parameter of the_title
to get it's output as a return value instead of it echo
'ing directly to the page, i.e.
$mytitle = the_title( '', '', false );
EDIT: Updated your code to show this in action:
<?php
if ( has_post_thumbnail() ) {
$title = get_the_title();
the_post_thumbnail("mini-me", array(
'class' => 'x-img smpic x-img-circle',
'alt' => $title,
'title' => $title,
) );
}
?>
本文标签: post thumbnailsarray set title and alt in thepostthumbnail
版权声明:本文标题:post thumbnails - array set title and alt in the_post_thumbnail 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744497429a2609115.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论