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 tried to apply filters to the_post_thumbnail() function using

apply_filters( 'post_thumbnail_html', $html, $post_id, $post_thumbnail_id, $size, $attr );

Here's the code I have come up with but doesn't seem to work completely

    function red_adjust_image_schema($html, $id, $caption, $title, $align, $url, $size, $alt) 
    $html = '<div class="image-container" itemprop="image">'. $html . '</div>';

    return $html;
add_filter('post_thumbnail_html', 'red_adjust_image_schema', 20, 8);

How can I add itemprop="image" to the actual image element so it registers properly? Right now it seem like I can only do a container and wrap around $html?


share|improve this question
up vote 1 down vote accepted

You've simply the wrong arguments (incl. the list of them).

$caption, $title, $align, $url, $alt

are too much in there.

And $attr is missing. Not that it matters how you name the vars (as long as they start with a character), but it's easier to read for later readers.

function wpse76536_image_schema( $html, $post_id, $post_thumbnail_id, $size, $attr ) 
    return "<div class='image-container' itemprop='image'>{$html}</div>";
add_filter( 'post_thumbnail_html', 'wpse76536_image_schema', 10, 5 );
share|improve this answer
Worked perfectly, thank you very much – Ryan Dennler Dec 19 '12 at 18:14

You can just add a new attribute:

add_filter('wp_get_attachment_image_attributes', 'ipwp_img_attr', 10, 2);
    function ipwp_img_attr($attr) {
    $attr['itemprop'] = 'image';
    return $attr;

This way there will just be a new attribute, without the need to search and replace any code - See my previous version:

add_filter('post_thumbnail_html','mediaboxlv_image_itemprop',10,3 );
function mediaboxlv_image_itemprop($html, $post_id, $post_image_id){
    $html = str_replace('src',' itemprop="image" src',$html);
    return $html;
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.