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 need to modify the_post_thumbnail function to run "Lazyload" on it, i think there is two solutions :

1- modify the args to be something like this

the_post_thumbnail('product', array('data-original'=>$src, 'src'=>'grey.gif'));


2- get only the image url from the function ... i've tried alot of snippets and nothing worked for me , like this one !

$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );

any ideas??


share|improve this question
up vote 2 down vote accepted

If you want to apply lazyload to each attachment image, you can just add your hoot to wp_get_attachment_image_attributes filter:

add_filter( 'wp_get_attachment_image_attributes', 'wpse8170_add_lazyload_to_attachment_image', 10, 2 );
function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) {
    $attr['data-original'] = $attr['src'];
    $attr['src'] = 'grey.gif';
    return $attr;

Or if you can use second approach:

$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );
// add more attributes if you need
printf( '<img src="grey.gif" data-original="%s"/>', esc_url( $thumbnail_src[0] ) ); 
share|improve this answer
Thanks alot,the add filter works like charm – johnmido Jun 12 '12 at 15:41
the second approach just like the second solution posted in my post , it just echos "Array" – johnmido Jun 12 '12 at 15:43
oups... already fixed :) – Eugene Manuilov Jun 12 '12 at 16:04
You are the man :) – johnmido Jun 12 '12 at 16:17
If you please, how to make add_filter apply only on specific registered '$size' s of attachments ? – johnmido Jun 16 '12 at 12:55

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.