{"id":8969499,"date":"2017-03-29T12:48:55","date_gmt":"2017-03-29T12:48:55","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/adding-srcset\/"},"modified":"2017-03-29T12:48:55","modified_gmt":"2017-03-29T12:48:55","slug":"adding-srcset","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/adding-srcset\/","title":{"rendered":"adding srcset"},"content":{"rendered":"<p>Hi Navneil,<br \/>\nThis is a very useful plugin.<br \/>\nI&#8217;ve added some extra code to add srcset capabilities in my local version &amp; wondered if you&#8217;d thought about doing the same, or if I could contribute the small changes I&#8217;ve made to your project.<br \/>\nThe implementation I have isn&#8217;t perfect as it requires the thumbnail size to be hard-coded in:<\/p>\n<pre><code>foreach($images as $image):\n\t\t\t$title = $image-&gt;post_title;\n\t\t\t$content = $image-&gt;post_content;\n\t\t\t$meta_data = wp_get_attachment_metadata($image-&gt;ID);\n\t\t\t$large_url = wp_get_attachment_url($image-&gt;ID, &#039;large&#039;);\n\t\t\t$large_srcset = wp_get_attachment_image_srcset( $image-&gt;ID,&#039;large&#039;, $meta_data);\n\t\t\t$thumbnail_url = wp_get_attachment_thumb_url($image-&gt;ID);\n\t\t\t$thumb_srcset = wp_get_attachment_image_srcset( $image-&gt;ID,array(150,150), $meta_data);\n\t\t\t$url = get_post_meta($image-&gt;ID, $field . &#039;_url&#039;, true);\n\t\t\t$target = get_post_meta($image-&gt;ID, $field . &#039;_target&#039;, true);\n\t\t\t$array[] = array(\n\t\t\t\t&#039;id&#039; =&gt; $image-&gt;ID,\n\t\t\t\t&#039;title&#039; =&gt; $title,\n\t\t\t\t&#039;caption&#039; =&gt; $content,\n\t\t\t\t&#039;large_image_url&#039; =&gt; $large_url,\n\t\t\t\t&#039;large_srcset&#039; =&gt; $large_srcset,\n\t\t\t\t&#039;thumbnail_image_url&#039; =&gt; $thumbnail_url,\n\t\t\t\t&#039;thumb_srcset&#039; =&gt; $thumb_srcset,\n\t\t\t\t&#039;url&#039; =&gt; $url,\n\t\t\t\t&#039;target&#039; =&gt; $target\n\t\t\t);\n\t\tendforeach;<\/code><\/pre>\n<p>Best wishes,<br \/>\nGuy<\/p>\n","protected":false},"template":"","class_list":["post-8969499","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8969499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/8969499\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=8969499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}