ACF Image Srcset

Hi,

There must be away someone has done this already, but I’m really struggling to find/work out the solution.

I have an image being pulled into a post using ACF reference:
<img src="[wpbb post:acf type='image' name='charity_image' display='alt']">

This works for showing the image, but I want to be able to use srcset to show the alternative sizes depending on the viewport.

I need to create a custom shortcode that would pull srcset images placed on any posts, using the following code taken from ACF https://www.advancedcustomfields.com/resources/image/#template-usage:
<?php
$image = get_field('image');
$size = 'full'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}

I also want to be able to use the alt tag for the image too.

Does anyone have a way to do this easily?
Many Thanks

I don’t know a way to pull ACF Image srcset from a Themer shortcode but the Custom Content Shortcode plugin does it easily:

[field image=charity_image]

It also pulls the image alt in the markup

Or you can drop a BB Photo module in the layout and use field connection from this module.
The markup will get the image srcset and alt tag.

Thanks for the tip, though that plugin hasn’t been updated for a while and I didn’t fancy installing another one. So, i worked out a custom shortcode to fix the issue, which can be seen here:

Thanks again
Rich

Well, CCS has been updated 4 months ago and regularly is, doesn’t seem particularly a while to me (and it depends on what’s in the plugin, all of them don’t need to be updated every week).

Also, just to say, if you had saw all what CCS can do with Themer in simple ways, maybe you would consider using it, instead of manually coding each time you need a little function. :slightly_smiling_face: