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.


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' )); ?>
|improve this answer|||||
  • 1
    the_post_thumbnail() escapes its own attributes, so it's not necessary here. – Jacob Peattie Aug 24 '19 at 11:45
  • Indeed, Cheers Jacob! – Lazar Momcilovic Aug 24 '19 at 11:59

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 ] )
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.