Add Attributes to Images via the_post_thumbnail

Sometimes you need to add a specific attribute to an image. You can do this quickly using the the_post_thumbnail function. The following snippet adds the itemprop="image" attribute to images, but you can also use it to add class, alt, title, etc.

the_post_thumbnail( 'thumbnail', array('itemprop'=>'image') );

For more on WordPress images, see Image Sizes in WordPress.

Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!