Skip to content
Advertisement

Add attribute to wp_get_attachment_image

I’m trying to add an attribute to the result of wp_get_attachment_image.

I want to use jquery lazyload to handle loading of my post thumbnails and to do that I need to add a data-original= attribute to the <img> tag wp_get_attachment_image is creating.

I’ve tried:

JavaScript

But it doesn’t add the data attribute as I expected.

JavaScript

Looking at the wp_get_attachment_image function it would seem that this ought to work though:

JavaScript

Where am I going wrong?

[update] Sometimes it just takes a fresh pair of eyes to spot the idiocy… Thanks to hobo I realised I simply missed out a parameter in my function call 😀 😛

Advertisement

Answer

I haven’t tested, but I think the problem is your array should be the fourth argument to wp_get_attachment_image, not the third.

So

JavaScript

should be

JavaScript

assuming you’re happy with the default value (false) of the $icon argument.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement