-
megmarrs
Hi there,
I have used ACF to create a custom “author_img” field, which is an image that is uploaded for each author, on their backend User page within WordPress.I want this image to get pulled on their custom author page. Right now the image block uses the Dynamic Data section to pull Data Source: Current Post > Image Source: Author Avatar. Is there any way to get to pull from the author_img field instead?
-
Hi there,
No, GB does not have the option to pull images from the author meta.
It might be easier to create a shortcode
[custom_author_image]
for it:add_shortcode( 'custom_author_image', 'create_author_image_shortcode_on_author_page'); function create_author_image_shortcode_on_author_page() { // Get the queried author object $author = get_queried_object(); // Get the author ID $author_id = $author->ID; // Get the user image for the author $image = get_field( 'author_img', 'user_' . $author_id ); // If the image exists, display it, change full to size you want if ( $image ) { return wp_get_attachment_image( $image, 'full' ); } else { return ''; // If no image is found, return empty string } }
Make sure the image field returns ID.
-
megmarrs
Thanks! Sorry, I’ve never created a custom shortcode. Where would I paste this code to create the custom shortcode? In a snippets plugin?
-
Yes, you can use the code snippet plugin 🙂
-
megmarrs
Hi Ying – I’ve gone ahead and set up the shortcode with that code you provided me in my snippets plugin. Can you help me understand where I should now use the [custom_author_image] shortcode? When I just use it in my custom author pages it doesn’t seem to work.
-
Can you provide an admin login to your site so I can check the backend?
-
megmarrs
Yes! Just added it in the private info section.
-
The pop-up login doesn’t work.
And I can not reset your WP login pw. If you don’t know what the password is, use a plugin like temporary login without password.
-
megmarrs
OK I updated the info – there was also a space in the pop-up login info, that’s why it didn’t work
-
Alvind
Hi there,
In your
author_img
ACF field, make sure the return format is set to Image ID.
- You must be logged in to reply to this topic.