WordPress.org

Forums

WP User Avatar
[resolved] Using image caption from media library? (4 posts)

  1. bahead
    Member
    Posted 1 year ago #

    When selecting an avatar from the WP Media Library, is there (or can there be) a hook to automatically display the caption associated with the image in the library?

    I'm using the WP Biographia plug-in with WP User Avatar, and I have a photo credit as the caption for the avatar image for each contributor. I'd like the photo credit to appear with the avatar.

    I'm sure I could figure out a hack but I'd prefer not to mess with the core WP User Avatar files.

    Bruce

    https://wordpress.org/plugins/wp-user-avatar/

  2. Bangbay Siboliban
    Member
    Posted 1 year ago #

    I'm not familiar with the WP Biographia plugin, but these are the ways available to add a caption if you can modify the structure of the biography display.

    You can add captions via the shortcode like this, if you want them to have the same layout as captioned images in your posts:

    [avatar user="admin" size="medium" align="left" link="file"]Photo Credit: Your Name[/avatar]

    In order to make this code dynamic, you'd have to put it directly in a template like this:

    <?php echo do_shortcode('[avatar user="'.$user_id.'" size="medium" align="left" link="file"]'.$caption.'[/avatar]'); ?>

    In order to get the caption that you've stored in your database, you would have to get the post_excerpt value of the attachment ID, which is stored in the usermeta table. You can get the value like this, if you pass the correct user ID which I'm assuming is the post author:

    global $wpdb, $blog_id, $post;
    $user_id = $post->post_author;
    $wpua = get_user_meta($user_id, $wpdb->get_blog_prefix($blog_id).'user_avatar', true);
    $caption = get_post_field('post_excerpt', $wpua);
  3. bahead
    Member
    Posted 1 year ago #

    Thanks for the quick response. I just realized that my issue is really with the WP Biographia plugin. I need to modify that plugin's code to display the caption along with the avatar from your plugin. Your tips will help.

  4. bahead
    Member
    Posted 1 year ago #

    I was able to make the changes I needed to the WP Biographia plugin using the approach you suggested. Captions are now displaying with the avatars. Thanks again for your help!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP User Avatar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.