Support » Plugin: WP User Avatar » Using image caption from media library?

  • Resolved bahead


    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.


Viewing 3 replies - 1 through 3 (of 3 total)
  • 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);

    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.

    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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Using image caption from media library?’ is closed to new replies.