-
-
Save pavlo-bondarchuk/4e58c19d14f9bde5af4cb6fb6e31db15 to your computer and use it in GitHub Desktop.
Wordpress srcset snippet for ACF image field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Use an ACF image field | |
| // Set the 'return value' option to "array" (this is the default) | |
| // This example uses three image sizes, called medium, medium_large, thumbnail | |
| $imageobject = get_field('image'); | |
| if( !empty($imageobject) ): | |
| echo '<img alt="' . $imageobject['title'] . '" src="' . $imageobject['sizes']['medium'] . '" srcset="' . $imageobject['sizes']['medium_large'] .' '. $imageobject['sizes']['medium_large-width'] .'w, '. $imageobject['sizes']['medium'] .' '. $imageobject['sizes']['medium-width'] .'w, '. $imageobject['sizes']['thumbnail'] .' '. $imageobject['sizes']['thumbnail-width'] .'w">'; | |
| endif; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment