Just use the the_post_thumbnail()
function. It creates the image tag, adds srcset
for you, and supports native lazy loading:
the_post_thumbnail( 'medium', [ 'class' => 'productimage' ] );
Related Posts:
- How do I change/modify the_post_thumbnail(); html output?
- Set the background to a default image if there isn’t a specified “featured image”
- Else/If Statement to Display Photo Descriptions
- add if statement to the featured image
- Remove default Image Sizes
- Generate and upload screenshot as featured image for user-submitted post
- What’s the best way to use the Featured Image for responsive web design?
- How to add a class to the attachment images
- How to draw media details for Isotope gallery using Photoswipe
- How to register images uploaded via FTP in media library?
- Adding Featured Image to Post programatically
- Add custom image sizes to media uploader
- How to upload imagick resource to media in wordpress
- How do I get images (with a thumbnail preview) to show in search results?
- Using wp_get_image_editor in a standalone script
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Assign a picture URL to a page via PHP
- Change logo based on incoming domain
- How to scale image with equal width and height without distortion?
- How to Display Image Meta underneath EVERY image in EVERY post
- Convert all images to PNG on file upload
- Echo URL of large version of Featured Image
- How to get specific image in media library with php
- Recent posts with featured image or fallback image with permalink
- How to control WordPress image metadata (using Imagick)?
- Scrape external webpage for first image and add it to new post
- Redirect to another page using contact form 7? [closed]
- height should be set to auto to avoid pixelation in the post thumbnail function
- Three Questions with Twenty Eleven theme
- Resize image to specific dimension (X to Y ratio)
- Get featured image with custom size outside WordPress
- How to set a featured image (thumbnail) with PHP?
- Image rotation issue (horizontal picture uploading as vertical) — Exif issue?
- Fallback image URL if no featured image exists via a shortcode function
- Generate responsive post thumbnails of same size
- How to Make Thumbnail of Post Stay Animated
- Get the alt text of the image in a array
- Adding a ‘style=’ bit to image_send_to_editor output
- Convert all uploaded PNG files to PNG-8 format
- Retrieve alt text by referencing the img src
- Add Featured Image to Existing Post
- How to use data URL in WordPress?
- Replace background image with post thumbnail in shortcode
- Resize post thumbnail
- How to put 2 php codes in functions.php without site crashing
- How to link all featured images to custom url in single.php for only non-logged-in users?
- How do I get the featured post to share on Social Media and show on Individual Post pages?
- Retrieving specific images from Media Library
- How do I routinely extract the thumbnail of the most recent post?
- insert thumbnail image from php script
- Can’t put a hyperlink on Featured Post’s Image
- add class to background image
- Extend the WP_Customize_Image_Control class to change its non-frame $button_labels
- My customizer’s setting doesn’t set to the default and needed to click the control’s “Default” button before it’ll be set
- Save the outputted image into the Media Library, with a different filename and extension
- Overwriting a Shortcode
- Setting post thumbnail sizes in template file and functions.php
- Understanding responsive imagery
- WooCommerce: write featured image dimensions to custom fields in product’
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- How to get the original price of the product in woocommerce?
- How to add a featured image to a existing post via php?
- How to add 2 posts under another post? Formatting should be intact
- Get widget settings function?
- Adding tawk.to code just before body tag on functions.php file
- add_action shortcut?
- ACF: how do I get the fields and its values of a specific group?
- Get page that displays all children of taxonomy parent
- Function to capture a value and store it in a variable
- Adding a widget function into the php theme file
- My new button is in the wrong place
- Checking array against author id in loop
- Call to undefined method – Download Monitor
- How do I link a button I created in theme customizer to a function?
- Random Featured Image Based on Category
- Read array in php?
- Tell WP register script to load a script only when the entire page is loaded
- Remove extract from function
- Undefined offset: 3 in custom function
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Can/should we delete wordpress cron jobs with no action?
- Database entry removed on browser refresh, Ajax PHP jQuery
- Display Visual Composer shortcode if a post belongs in specific categories
- HTML comment cause issue in functions.php script root
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- WordPress Ajax filter: Create two loops for different output styles?
- How to call a function from functions.php with ajax?
- Set user status to absent on WordPress
- Get the image title and alt from custom query
- Showing wordpress latest post thumbnails in slider with auto increment
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Limit Taxonomy Parents
- WordPress HTML Helper
- List sibling pages widget, exclude current page
- How to add button to top of theme customizer?
- Send foreach $_post method to contact form 7 [closed]
- Options.php loop won’t show!
- How do I stylize selected comments?