You got everything you need, simply build your own img
-element like this:
if ( has_post_thumbnail() ) {
$class="lazy attachment-thumbnail-400-300";
//Get thumbnail source
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail-400-300');
$src = $thumb['0'];
$placeholder = "//placehold.it/400x300/eee/222/&text=+";
echo '<img src="'.$placeholder.'" data-original="'.$src.'" class="'.$class.'" />';
}
Besides that, your main performance issue might be generating a new placeholder every time you want to display an image. Use a local file for that, it´s only a few bytes in size but saves you that extra request (with all the overhead).
Related Posts:
- Is there a hook which fires after all thumbnails are generated?
- get_the_post_thumbnail_url with an unregistered size
- Cropped featured image replaces original image in gallery
- No srcset for hard-cropped thumbnails
- Removing Title Tag from Thumbnails
- Disable wordpress image sizes generation
- How to stop thumbnail generation from some images and different size thumbnail generate
- Update old Post image metadata to ‘thumbnail’ wp_attached_file
- How to stop wordpress always displaying full-res images
- Fixing image names for a site being restored
- Filter for post_thumbnail: link to small src and add data-attribute [duplicate]
- Can we use featured image as third party website image URL
- add_image_size not working
- Product Images Low Quality After Updating From WP 3.5 to 4 [closed]
- adding image to post thumbnail from another server
- How to add thumbnails to posts and pages automatically in a uniformed fixed elegant way?
- How to use default image as featured image by implement some code in function.php
- WordPress Multisite: Images moved to /sites/1?
- I cannot upload images to post or the media library in wordpress
- Why image Thumbnail url is not displaying with custom size?
- Making a thumbnail if there exist a link with. jpg or .png extension in WordPress
- WP is showing wrong image dimensions
- Programmatically get images by URL and save in uploads folder
- the_post_thumbnail responsive srcset not populating with custom image size
- How to change image type for specific size?
- is it possible to replace the use of gd_lib with imagick or ImageMagick?
- Change WordPress image URLs via filter
- Insert an image into a post by API
- set_post_thumbnail_size not cropping featured images, but reducing proportionally
- How to grab first image attached to post and display in RSS feed?
- Double thumbnails?
- Can’t Display Featured Image in RSS Feed
- Displaying a featured image (only img url) as the img src?
- When displaying the featured image, is has_post_thumbnail() necessary?
- Get original image from thumbnail URL
- WP 3.4 has missing photo data
- Save image as featured image
- Thumbnails produce unwanted gray pixels on white background [closed]
- Image Quality Thumbnail Compression in WordPress?
- WordPress reduces the full size image and uses it as the original
- How check that there is post thumbnail feature image or not on wordpress?
- Woocommerce featured image of page – not product
- Set Post Image Using Shortcode
- Print specific image size in galley loop
- Can’t seem to attach uploaded image to post and set it as thumbnail
- Store Snapshot created via wordpress to use with lightbox
- How can I add a “data-pin-nopin” the featured image html?
- how to link post-thumbnail to original img in a lightbox?
- Add padding while generating thumbnail
- Can’t generate thumbnail images
- How to make thumbnails of uploaded animated gifs NOT animated
- “Medium” size image displayed instead of “thumbnail” in only one post, other posts are fine
- Custom Loop, Match Category with Page: How to display post featured image?
- How to fit image to Thumbnail canvas size?
- Generate images to be associated for tag and category?
- How do I get my main image to stretch the full length of the screen?
- Bulk-add featured images in posts with no featured image
- Why doesn’t WordPress use the smaller sized image?
- How to set featured image from external url programmatically
- Get an image from url, resize it, and save on a custom folder (not the media library)
- Else/If Statement to Display Photo Descriptions
- Remove Additional image sizes created by theme
- Dynamically determine the width and height of a image file to be cropped & uploaded AFTER form submission given fixed aspect ratio
- Set two default featured images
- Placing a featured image into header
- resize and crop thumbnail photos
- Broken thumbnails (sometimes) with TimThumb
- Is it possible to save crop to a different size of the image when in image editor?
- How to only show div of caption if caption exists on featured image
- Apply manual image cropping not to thumbnail but medium_large size
- Display Multiple Photos as Featured Image when mouse moves on to it post
- How to echo images Urls from a wordpress post, that are relally in the post
- WordPress Responsive Image ( srcset ) not work properly
- How to Display Image Caption but Not Alt Text
- Image alt attribute
- Images missing from Blog post page
- How to set a post featured image from an already made custom field
- Why does wp_get_attachment_image_src return the wrong size, when the correct size exists?
- New portfolio items appearing smaller on the grid
- stop wordpress from resizing feature gif images
- second featured post not displaying on page [closed]
- Does WordPress have a way of changing the ‘Natural’ size of uploaded images?
- WooCommerce Variation Swatches and Photos – get attribute thumbnail
- set_post_thumbnail_size only working for width
- Newly uploaded images are not updating in featured image
- Troubles with code for upload a image
- Image thumbnail on single product issue | WooCommerce
- Create a custom attachment thumbnail for quick page load
- get the post thumbnail returns the full size
- Why are my ‘medium’ images the wrong size
- How do I get resized thumbnails?
- Why is WordPress loading a different sized post thumbnail?
- Create post thumbnails from images stored outside of uploads directory
- Using the on-board image editor for featured images: edits are not being used
- Tried everything but Facebook share button won’t load the post thumbnail
- has_post_thumbnail() Returns False on Scheduled Posts
- Why some images are not allowed to be edited only for thumbnails?
- Delete all thumbnails & regenerate them?
- WordPress pointing animated GIF images with wrong file name upon upload (GIFs animation not working)
- Edit multiple posts featured image