0

I'm using advanced custom fields and have setup an image field for my users to add an image in their profile. I'd need to display this image on post pages, so i've tried the following...

<?php
$attachment_id = the_author_meta('author_logo');
?>
<?php echo the_author_meta('author_logo'); ?>
<?php wp_get_attachment_image_src( $attachment_id )?> 
<?php wp_get_attachment_url( $attachment_id ); ?>

The output is always the image attachment ID never the URL. What can I change to output the image path URL?

Thanks

1

From codex:

The the_author_meta Template Tag displays the desired meta data for a user. If this tag is used within The Loop, the user ID value need not be specified, and the displayed data is that of the current post author. A user ID can be specified if this tag is used outside The Loop.

If the meta field does not exist, nothing is printed.

NOTE: Use get_the_author_meta() if you need to return (not display) the information.

So, replace the_author_meta() with get_the_author_meta(). You can then use wp_get_attachment_image() to get an image element ready for outputting to the page.

<?php 
$id = get_the_author_meta('author_logo');
if ($id) {
    echo wp_get_attachment_image($id);
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.