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"https://wordpress.stackexchange.com/questions/54986/,"wpse8170_add_lazyload_to_attachment_image', 10, 2 );
function wpse8170_add_lazyload_to_attachment_image( $attr, $attachment ) {
$attr['data-original'] = $attr['src'];
$attr['src'] = "https://wordpress.stackexchange.com/questions/54986/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="https://wordpress.stackexchange.com/questions/54986/grey.gif" data-original="%s"/>', esc_url( $thumbnail_src[0] ) );
Related Posts:
- How to Dynamically Resize WordPress Image On-The-Fly (custom field/theme option)
- How do I regenerate thumbnails?
- Add Title Attribute to WordPress Image the_post_thumbnail
- media_sideload_image generates blank?
- Post thumbnail outside the loop
- How do I add the featured image to the_content after the first paragraph?
- Showing a placeholder/default img, if no featured image is set
- Re-order media links?
- How to show featured image CAPTION only if it exist
- Add Image Dimensions to Media Library Tab on Media Upoader
- Featured image for news page
- Fallback default image when there is no featured image
- Adding schema itemprop image to the_post_thumbnail with filters
- How to get custom image sizes into media uploader dropdown?
- wordpress responsive image srcset not working
- Possible to swap in a placeholder image globally for the_post_thumbnail_url if one doesn’t exist?
- How do I get a random image from subset of images in media gallery?
- How to use wp_get_attachment_metadata for thumbnails
- Why are extra 92 pixel square thumbnails created?
- wp-cli regenerate media is not working for custom sizes
- Remove dimensions from filename featured image
- Can a thumbnail of an animated gif be animated?
- PDF Image in content
- Why does the Hard Crop option Scale?
- Post Thumbnails multiple sizes
- Long Post Title Misaligning Grid with Featured Image
- How to add multiple featured images to post/page without a plugin
- How do I set “Upload Image” as detault “Set Featured Image” window?
- Featured Image won’t display on Posts page
- Get post thumbnail from subpages with a foreach loop
- Getting images to show up in RSS Reader
- how i can increase Featured thumbnails size?
- the_post_thumbnail() Custom sizes not display correctly
- Set_post_thumbnail not resizing images
- How to inject attributes into get_the_post_thumbnail?
- MultiPostThumbnails for Custom Post Type
- Muliple featured images (or just images) per post
- Featured image for first post only
- WordPress Featured Image function recreate
- Using Featured Image as Hero Background
- wp_get_attachment_image_src match smallest edge
- Can’t Set Featured Image [closed]
- Resize post thumbnail produces horrible image quality..Any help?
- media-library: how to insert thumbnails with a fixed width, regardless of landscape/portrait orientation
- Post thumbnail outside of loop
- How to query posts with featured images
- query_posts adding two “post-entry” divs
- Display a thumbnail outside of the loop for a page
- Server B handling add_image_size() differently than Server A
- How to use get_the_title with text on the ‘alt’ of the_thumbnail array?
- remove_image_size doesn’t seem to be working
- Get Featured Image Outside Loop Not Working
- Responsive scaling of image for the_post_thumbnail() [closed]
- Choose to Display Post Thumbnail?
- images not showing despite using add_theme_support(‘post-thumbnails’);
- post thumbnail: increase dimension if smaller than… Possible?
- Displaying caption with featured image
- add_theme_support post-thumbnails not working
- Trying to show WordPress category query result as background image
- How risize a thumbnail?
- custom thumbnail image size not working
- Comparison Operators not working for conditional author post thumbnails
- Assign SQL ‘post_thumbnail’ column as featured image
- Default thumb – how to set it
- the_post_thumbnail(‘medium’) still gives thumbnail-size img
- How to update custom image sizes?
- featured images twenty eleven theme
- Picture inserted in the post not showing in “Gallery”
- featured image is not showing
- How do you code a featured image into an XML as a jpg link, instead of using a data-id number?
- How to change the format of thumbnails into wordpress theme?
- How to calculate the sum of all featured thumbnail height on WordPress?
- How to create thumbnails programmatically?
- Using the_post_thumbnail do not rollback to original image if specified thumbnail does not exist
- Get author image from corresponding article in thumbnail
- Usage of add_image_size (for featured image)
- Featured image: Dynamic image sizes when enlarged with javascript
- water mark on featured post image in wordpress
- Smaller Size for featured images
- Featured image doesn’t appear in Blog index
- Genereate widescreen featured images in different sizes
- Remove Featured Image based on Date
- How to show only 2nd featured img on home/blog
- Echo recent posts each with its own respective featured image
- How to get the URL of a each custom image size of a featured image
- Add Featured Image from Existing wp-content folder
- How to get post thumbnail to be equal to set media size
- Add notice to add image popup
- Mass/Bulk assign featured images to posts
- setting featured image is not working while running script in background, works when running that script from browser
- Editing featured image
- How to modify responsive images in post thumbnails
- get_the_post_thumbnail() – Invalid argument supplied for foreach() in /wp-includes/post-thumbnail-template.php on line 64
- Different thumbnail size than actual picture in post
- Scan for first image in post and display it [duplicate]
- How to get the featured image inside of a single-.php template?
- Where is the template from the_post_thumbnail()?
- Get Post Thumbnail Outside of Loop
- Theme:Twenty Fourteen, How to remove featured image on single post page for particular category
- Why not attaching images after impoting using wp cli