I’m using advanced custom fields and set an image upload field in user profiles. I’m using this image a few places on the website and need to set a custom size for it on some pages.
If I set add_image_size( 'homepage-thumb', 190, 259, true );
in my functions file how can I use this image size with the uploaded image since it’s not a featured post or page image?
From my home page this is how I get the image
$author_logo = get_field('author_logo' , 'user_' . $author_id ); // image field, return type = "Image Object"
then <img src="<?php echo $author_logo;?>" />
Thanks
Your first problem is that custom field is saved as url, and not as id. So you need to retrieve the attachment id from the url. First tentation is to use the ‘guid’ field.
Resist the temptation and find another way: for robust wordpress code you have to think ‘guid’ not exists, so repeat with me: “guid does not exist”.
Once ‘guid’ does not exists we have to find another way, this good one, come from here
Then we use previous function to wrire another one:
After you saved these function in a plugin or in theme
functions.php
you can use them in this way:Code is untested but should works, unless any typo…
This might work if it is the full size image url you are storing in your custom field. Try to place this function in functions.php
then get the image this way
and then
More info: wp_get_attachment_image_src