WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a website made with wordpress which includes recipes. Now I would like to add the "photo" hrecipe Microformat tag in order to have a thumbnail on Google searches (hrecipe photo tag)

My recipes pictures come from the featured image section. How can I now add itemprop="photo" to the <img> tag?

For example:

  <img itemprop="photo" src="apple-pie.jpg" /> 

This is were my Thumbnail is created:

<div class="post-thumb">

    <?php if( !is_singular() ) { ?>
        <a title="<?php printf(__('Permanent Link to %s', 'zilla'), get_the_title()); ?>" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('blog-large'); ?></a>

    <?php } else {

    } ?>

share|improve this question
up vote 2 down vote accepted

Use the filter post_thumbnail_html. The callback takes 5 parameters, the first ($html) is the one that's returned and that we modify, and the others can be helpful to build the modification.

add_filter( 'post_thumbnail_html', 'add_tag_to_featured_wpse_95469', 10, 5 );

function add_tag_to_featured_wpse_95469( $html, $post_id, $post_thumbnail_id, $size, $attr )
    $modify = str_replace( '<img', '<img itemprop="photo"', $html );
    return $modify;

Relevant Q&A: Where to put my code: plugin or functions.php?

share|improve this answer

from Adding schema itemprop image to the_post_thumbnail with filters :

add_filter('wp_get_attachment_image_attributes', 'ipwp_img_attr', 10, 2);
function ipwp_img_attr($attr) {
  $attr['itemprop'] = 'photo';
  // OR better 
  // $attr['itemprop'] = 'image';
  return $attr;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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