最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

post thumbnails - How to use get_the_title with text on the 'alt' of the_thumbnail array?

programmeradmin1浏览0评论

I'm currently using <?php the_post_thumbnail('250px', array('class'=>"review-siteshot", 'alt' => get_the_title() )); ?>

I know that 'alt' => "review" will output review as all text.

I'm trying to use get_the_title() along with "review" so that I get title-text review as my alt text for the thumbnail.

I'm currently using <?php the_post_thumbnail('250px', array('class'=>"review-siteshot", 'alt' => get_the_title() )); ?>

I know that 'alt' => "review" will output review as all text.

I'm trying to use get_the_title() along with "review" so that I get title-text review as my alt text for the thumbnail.

Share Improve this question asked Aug 24, 2019 at 10:37 BikramBikram 3386 silver badges22 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Like this:

'alt' => get_the_title(). ' review'

So the full code would be:

<?php the_post_thumbnail('250px', array('class'=>"review-siteshot", 'alt' => get_the_title(). ' review' )); ?>

The function the_title() can be used to append a string and to return instead of echoing:

the_title( '', ' review', 0 )

In case stripping tags and escaping is necessary, the function the_title_attribute() can be used:

the_title_attribute( [ 'after' => ' review', 'echo' => 0 ] )
发布评论

评论列表(0)

  1. 暂无评论