I’ve been searching and trying code for hours and hours, I just can’t get this to work properly, hoping someone can help me understand the Image Field better?
I need to use either the default Thumbnail size or a custom size image for use with the Image field (since you can’t select an image size, from what I can see.) For this example, I’m trying to use a custom image size. I am using an Image Field set to return the Image URL.
Here is my code in the functions.php file, for a custom image size:
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'homepage-thumb', 97, 83, true );
}
add_filter( 'image_size_names_choose', 'my_custom_sizes' );
function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
'homepage-thumb' => __('Homepage Thumbnail'),
) );
}
This is my code in the template:
<?php if ( get_post_meta($post->ID, 'button_one_link', true) ) : ?>
<?php
$attachment_id = get_field('button_one_image');
$size = "thumbnail";
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
?>
<li><a href="<?php the_field('button_one_link'); ?>"><img src="<?php echo $image[0]; ?>"><?php the_field('button_one_text'); ?></a></li>
<?php endif; ?>
The frontend doesn’t show anything, no image at all.
I’m not sure what I’m doing wrong 🙁
Thanks~