Hi Mahdi,
wp_get_attachment_image will return a srcset
If you sent the attachment_id and use a size that isn’t the smallest so medium, full or any you have defined it will then get a srcset, you can even define which image sizes you would like by supplying an array of image sizes to this.
wp_get_attachment_image($image_id, ‘medium’);
or
wp_get_attachment_image($image_id, array(‘medium’, ‘full’));
Cheers
James
Thread Starter
Mahdi
(@mahdiyazdani)
Thanks for the answer @paralleljames
So far tried this one and it caused a PHP error on the front-end.
wp_get_attachment_image($image_id, array('medium', 'full'));
Warning: A non-numeric value encountered in /XXX/4/0/7/XXXX/httpd.www/dev/wp-includes/media.php on line 647
Have you set $image_id as the id of the attachment?
Where have you set the image? Is this your featured image? or do you have a custom field?
Thread Starter
Mahdi
(@mahdiyazdani)