i use this code to show post’s thumbnail in my site but this code cant show the title Attribute of the thumbnails.
how can i add Title Attribute to WordPress thumbnails?
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('large');
} else {?>
<img alt="<?php the_title(); ?>" title="<?php the_title(); ?>" src="<?php bloginfo('template_url'); ?>/img/thumbnail.png"/>
<?php }?>
you can see my site with this url : http://rokesh.ir
You can do that because you can add all the attributes you need:
Please read on in the Function Reference of the_post_thumbnail.
As per the Codex entry for
the_post_thumbnail()
, you can pass an attributes array as a parameter:So you would just need to define the array; here’s the Codex example, modified to include the
title
attribute:…which you could then pass to
the_post_thumbnail()
: