wordpress responsive image srcset not working
I'm trying use wordpress core responsive image feature but it's not adding srcset to image. Here is th my codes
I have a div w=370px h=280px now I added image sizes
if(function_exists('add_image_size')){
add_image_size( 'imagebox', 370, 280, true );
add_image_size( 'imagebox-2x', 840, 560, true );
add_image_size( 'imagebox-3x', 1110, 840, true );}
And calling it inside the loop like this
the_post_thumbnail('imagebox-2x');
it's adding only image like this 2x version without srcset
img width="840" height="560" src="http://localhost/starter/wp-content/uploads/2018/10/04004_theblackandwhiterocky_2560x1600-840x560.jpg" class="attachment-imagebox-2x size-imagebox-2x wp-post-image" alt=""
If I remove the image size from the_post_thumbnail and use it only the_post_thumbnail(); it's working with responsive images but without my sizes
img width="180" height="180" src="http://localhost/starter/wp-content/uploads/2018/10/04004_theblackandwhiterocky_2560x1600-180x180.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" srcset="http://localhost/starter/wp-content/uploads/2018/10/04004_theblackandwhiterocky_2560x1600-180x180.jpg 180w, http://localhost/starter/wp-content/uploads/2018/10/04004_theblackandwhiterocky_2560x1600-150x150.jpg 150w" sizes="(max-width: 180px) 100vw, 180px"
How can I fix this?
Topic responsive post-thumbnails images Wordpress
Category Web