WordPress has supported Gravatars for awhile, which is great, but if you’re rolling out a site for a bunch of students to hammer on, it’s not ideal to have to send them to a third party service to set up photos. It’s awkward, and confusing, for new users to have to go somewhere else to add a photo to their profile. And profile photos can be very useful, especially at the beginning of a semester when everyone is just getting to know everyone else in a class, to put a face to a name.

So, for UCalgaryBlogs.ca, I just installed the handy User Photo plugin. Now, any site can enable this, and the users of that site will be able to add photos to their profiles, like this:

The plugin can be configured with custom sizes for the full-size and thumb versions of the avatar, and the avatar image can be deleted and/or replaced at any time.

It’s not completely trivial to enable - because the themes need to be User Photo aware. That’s pretty easy to add, though. For the cutline theme we’re using on a project, I edited a handful of files to add the code, and it works great. On index.php, and single.php, just add this wherever you want the blog author’s photo to be displayed on the post (I put it in the section displaying the post meta information):

<?php if (function_exists('userphoto_the_author_thumbnail')) {  userphoto_the_author_thumbnail();}?>

Wrapping the thumbnail display code in a function_exists conditional means it will degrade nicely if the plugin is unavailable. Always a good thing to degrade instead of borking.

That results in this display when viewing the post:

Now, if you also want to show avatars on the comments, just edit comments.php to add this code (I put it in the comment meta info section):

<?php if (function_exists('userphoto_comment_author_thumbnail')) { userphoto_comment_author_thumbnail();}?>

And that will look like this when displayed on the blog:

If a user hasn’t added an avatar, it won’t display any image. But if they do have one, they’ll get the properly sized version of their avatar image displayed automatically. Easy peasy. It’s a bit awkward having to edit the themes, but it’s not difficult. The hard part will be remembering to re-apply the edits if the themes get updated (hence this post…)

Comments

5 Responses to “User Avatar Photos in WordPress”

  1. Rob Wall on September 3rd, 2008 10:08 pm

    Where did you get the avatar you’re using in this post?

  2. dnorman on September 3rd, 2008 10:10 pm

    I created it with faceyourmanga.com - it’s not entirely accurate, but as good as I could do with the options available…

  3. Phil on September 16th, 2008 7:34 am

    Sorry guy but I’m not able to display the user photo in comments, I do not see where to put the code after activating the plugin.
    Can I post you the comments.php template I have so you can help me?

  4. Sreejith K on October 15th, 2008 2:01 am

    Thanks for this tip

  5. groq on October 22nd, 2008 9:10 pm

    Hi,

    I’ve got the plugin installed on my blog, wp version 2.6. I’m currently working on a page that displays a list of all my subscribers. I would like to show the photos of my subscribers in these results. the code I currently use, results in the photo of the author of the page being displayed for each subscriber. snippet of code below:

    display_name; ?>

    description; ?>

    Am I using the code right? Any help would be greatly appreciated. Thanks in advance.

    -Groq

Leave a Reply

You must be logged in to post a comment.

Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 Canada License.