• Resolved ugy

    (@ugy)


    Hi Navneil,
    This is a very useful plugin.
    I’ve added some extra code to add srcset capabilities in my local version & wondered if you’d thought about doing the same, or if I could contribute the small changes I’ve made to your project.
    The implementation I have isn’t perfect as it requires the thumbnail size to be hard-coded in:

    foreach($images as $image):
    			$title = $image->post_title;
    			$content = $image->post_content;
    			$meta_data = wp_get_attachment_metadata($image->ID);
    			$large_url = wp_get_attachment_url($image->ID, 'large');
    			$large_srcset = wp_get_attachment_image_srcset( $image->ID,'large', $meta_data);
    			$thumbnail_url = wp_get_attachment_thumb_url($image->ID);
    			$thumb_srcset = wp_get_attachment_image_srcset( $image->ID,array(150,150), $meta_data);
    			$url = get_post_meta($image->ID, $field . '_url', true);
    			$target = get_post_meta($image->ID, $field . '_target', true);
    			$array[] = array(
    				'id' => $image->ID,
    				'title' => $title,
    				'caption' => $content,
    				'large_image_url' => $large_url,
    				'large_srcset' => $large_srcset,
    				'thumbnail_image_url' => $thumbnail_url,
    				'thumb_srcset' => $thumb_srcset,
    				'url' => $url,
    				'target' => $target
    			);
    		endforeach;

    Best wishes,
    Guy

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘adding srcset’ is closed to new replies.