Last active
August 17, 2022 15:32
-
-
Save sabotawsh/15ad8056e87cc8baa4f174d273921f89 to your computer and use it in GitHub Desktop.
When using Advanced Custom Field plugin for WordPress, this allows you to target custom image sizes
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 | |
$attachment_id = get_field('image'); | |
$size = "square"; | |
$image = wp_get_attachment_image_src( $attachment_id, $size ); | |
?> | |
<img alt="Image of <?php the_title(); ?>" src="<?php echo $image[0]; ?>"> | |
// IF GROUP | |
<?php | |
$attachment_id = get_sub_field('image'); | |
$size = "square"; | |
$image = wp_get_attachment_image_src( $attachment_id, $size ); | |
?> | |
<img alt="Image of <?php the_title(); ?>" src="<?php echo $image[0]; ?>"> | |
// IMAGE ARRAY | |
<?php | |
$image = get_sub_field('image'); | |
$image_url = $image['sizes']['slider']; | |
$size = "slider"; | |
?> | |
<img src="<?php echo $image_url; ?>" alt="<?php echo esc_attr($image['alt']); ?>"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment