Add Title Attribute to WordPress Image the_post_thumbnail

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?

Read More
<?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

Related posts

2 comments

  1. As per the Codex entry for the_post_thumbnail(), you can pass an attributes array as a parameter:

    <?php the_post_thumbnail( $size, $attr ); ?>
    

    So you would just need to define the array; here’s the Codex example, modified to include the title attribute:

    $post_thumbnail_attr = array(
        'src'   => $src,
        'class' => "attachment-$size",
        'alt'   => 'alt here',
        'title' => 'title here',
    );
    

    …which you could then pass to the_post_thumbnail():

    the_post_thumbnail( 'large', $post_thumbnail_attr );
    

Comments are closed.