In a recent custom WordPress build I needed to add microdata to all images output by the_post_thumbnail inside of a custom template and where a catch all function did not make sense.

Specifically I needed to add itemtype=”photo” to thumbnail images associated with a “Place” in a custom place listings template but these are implementation specific details that will vary based on your needs.

As it turns out, adding microdata to WordPress thumbnail images using the_post_thumbnail function is actually quite easy. You can accomplish this by using the $attr parameter of the_post_thumbnail function.

In the example below “image-size” is the required thumbnail size parameter and itemprop is the microdata attribute pair specified in the $attr parameter.

Again, these values will depend on your requirements.

This is a very simple, no frills implementation but it get’s the job done.