Adding User Photo to WordPress User Profile

The times they are a-changin’.

This post seems to be older than 14 years—a long time on the internet. It might be outdated.

I finally got around to packaging up the Add User Photo plugin. You can download it here. Go to the plugin page, Add User Photo, to grab the latest copy. Unzip it and upload to your plugins directory, and then activate it. You also need to modify line 21 of /wp-admin/profile.php, adding enctype="multipart/form-data" to the form tag.

So at the end of the day, line 21 should look like:

<form name="profile" id="your-profile" action="profile-update.php" method="post" enctype="multipart/form-data">

63 thoughts on “Adding User Photo to WordPress User Profile”

  1. Pingback: Jeff McNeill

  2. Brilliant !

    Seems to be working, but I’m note sure what piece of code to use in order to display the picture in the front office. If you can manage to add this info, you’re a king ! 🙂


  3. OK, I’ve found out something working:

    user_login;?>.jpg?rand=” height=”100″/>

    Not sure if it’s the right thing, but working.

  4. Including the picture depends on how you want to call it.

    If you want to include code, you have to escape it. You can also surround it with [html]Your code here[/html]

    The output will look something like:

    Your code here
  5. The project I designed this for is my schools Radio Website ( Users are listed by their user_ID, so when their profile is viewed, a quick lookup finds their user_login.

    Once the user_login is found, I use the PHP file_exists() to determine if the user has uploaded an image. If they have, it uses that. If not, it uses a generic image.

    Also, the WordPress Database class is a very powerful way to interface with the DB. This is the best way to get the information you need.

  6. Pingback: foto do usuário no wordpress - athanazio

  7. Hi Andrew:

    Great idea. Unfortunately I tried uploading a photo and got the following errors when I clicked the “Update Profile” button:

    Warning: move_uploaded_file(/homepages/8/d104609365/htdocs/dev4//wp-content/images/admin.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpMrUKie’ to ‘/homepages/8/d104609365/htdocs/dev4//wp-content/images/admin.jpg’ in /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: Cannot modify header information – headers already sent by (output started at /homepages/8/d104609365/htdocs/dev4/wp-content/plugins/fergcorp_addUserPhoto.php:61) in /homepages/8/d104609365/htdocs/dev4/wp-includes/pluggable-functions.php on line 272

    Any ideas? The filename I’m trying to upload is agent.jpg.

    Thanks – Michael

  8. First off, thanks for the hard work, this is exactly what I need. I’m trying to integrate this with wordpress MU, and I’m having some difficulties. Basically, I want to display the user’s picture in the sidebar, but for some reason the .$profileuser->user_login part of the img src url isn’t returning anything. The path is fine, just nothing returned for the user_login. Do you have any ideas? I don’t know if MU accesses user_login differently, or even if I can get to that variable from the front side. Any help would be appreciated.

  9. never mind, I was off on what I needed. I’ve re-read the code and understand what’s happening now.

  10. Pingback: WordPress › Author Image plugin? « WordPress MU Forums

  11. Not sure if anyone else ran into this problem, but if you try to upload a picture and it keeps giving you an error message about the file being a pjpeg instead of a jpg just change line 60 of the plugin code to show the following:

    if(($_FILES[‘photoUpload’][‘type’] == “image/jpeg” or “image/pjpeg”) || ($_FILES[‘photoUpload’][‘type’] == “image/jpg” or “image/pjpeg”)){

    And then it should work fine.

  12. Actually, you should you should use:

    if(($_FILES['photoUpload']['type'] == "image/jpeg") || ($_FILES['photoUpload']['type'] == "image/jpg") || ($_FILES['photoUpload']['type'] == "image/pjpeg")){
  13. Andrew, even after modifying line 60 of fegcorp_addUserPhoto.php to be : 1.
    if(($_FILES[‘photoUpload’][‘type’] == “image/jpeg”) || ($_FILES[‘photoUpload’][‘type’] == “image/jpg”) || ($_FILES[‘photoUpload’][‘type’] == “image/pjpeg”)){

    an upload of a jpeg file returns:

    Error: Please only upload jpg files! Your content type is

    Please go back and try again.

  14. Hi Andrew, thanks for that great plugin! Could you please write here the piece of code I should use to show the photo of a post author on single.php page? Thanks in advance.

  15. I get this error when trying to upload a .jpg image:

    “Error: Please only upload jpg files! Your content type is

    Please go back and try again.”

    Any ideas?

  16. After using this for a while, I realized that since it runs your function every time you update your profile, when I go into the profile just to change some other field but not to update my picture, it still tries to upload something and I get an error because it’s not jpg or jpeg. Can something be written in there to test for a blank field or perhaps a checkbox the user checks everytime you wish to upload a new picture?

  17. I just wanted to echo the request for some examples of code that will display the user’s photo on an author template, or in the sidebar. Also, I am curious if this could be used in the comments to display the photo next to an author’s comment. Kind of like the gravatar stuff. Thanks in advance.

  18. If anyone is interested, this is what I got to work on an author profile template:

    <img src="<?php echo get_bloginfo(‘url’)."/wp-content/images/".$curauth->user_login; ?>.jpg?rand=<?php echo rand(); ?>" height="100" align="right" />

    I am still trying to get it to work in the comments…

  19. To get this to work in the comments, you can use this plugin:

    Once you have this installed you could put this code in your comments template:

    if(is_wpuser_comment() != 0) {
    echo "<a href=’http://www.yourblogaddress/author/".comment_wpusername()."’><img
    echo rand(); height=’100′ width=’100′ alt=’User Photo’ align=’left’ /> </a> "; } ?>

    Not knowing a lick of php, I surprised myself that I could make this work…

  20. I just realized that I have the same problem as Gilbert with the error when I try to update anything on my profile without putting anything in the upload photo field. Has anyone found a solution to this problem?

  21. Hey all,

    I just want to let you know that I am here and reading your comments. I been really busy with school and what not, but I have a break in about two weeks. I’m hoping to take a look at the code then.


  22. I was also looking for a way to prevent the error message if I did an update without including another upload image. So I included a parent if statement to see if the file type is null, in which case it will not execute the upload.

    I also added a ‘chmod’ command to set the file permissions once the file is uploaded, since i was having trouble with this the way my server is configured.

    if ( $_FILES['photoUpload']['type'] != "" )  {  if(($_FILES['photoUpload']['type'] == "image/jpeg") || ($_FILES['photoUpload']['type'] == "image/jpg") || ($_FILES['photoUpload']['type'] == "image/pjpeg"))    {      move_uploaded_file($_FILES['photoUpload']['tmp_name'], ABSPATH."/images/".$userdata-&gt;user_login.".jpg");
          chmod(ABSPATH."/images/".$userdata-&gt;user_login.".jpg", 0644);
        //die("error: ".$_FILES['photoUpload']['error']);
        die("<strong>Error:</strong> Please only upload jpg files! Your content type is <code>".$_FILES['photoUpload']['type']."</code>Please <a href='history.go(-1)' rel="nofollow">go back</a> and try again.");

    I hope this helps.

  23. Pingback: Blogging - RenegadeLatinoWiki

  24. Thank you for the plugin.
    In Kevin’s last ZIP, the wp-content folder is missing in the path.

    //Change this line                  chmod(ABSPATH."/images/".$userdata->user_login.".jpg", 0644);
    //for this one:
    chmod(ABSPATH."/wp-content/images/".$userdata->user_login.".jpg", 0644);
  25. Thanks for the plugin, but I cannot seem to get it to work.

    I get an error whenever I try to upload my image:

    Warning: move_uploaded_file(/home/peoriapu/public_html/blogpeoria//wp-content/images/peoriap.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/peoriapu/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpeojTv7’ to ‘/home/peoriapu/public_html/blogpeoria//wp-content/images/peoriap.jpg’ in /home/DELETED/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php on line 61

    Warning: Cannot modify header information – headers already sent by (output started at /home/DELETED/public_html/blogpeoria/wp-content/plugins/fergcorp_addUserPhoto.php:61) in /home/DELETED/public_html/blogpeoria/wp-includes/pluggable-functions.php on line 272

  26. sorry for a stupid question, I’m just bit lost on this one. how can I load the updated image? fex in to the author sidebar?

  27. Pingback: WPMU Author Profile Enhanced Plugin : The Almighty and His Servant

  28. Fantastic plugin…….. Have made a slight change so that as admin on the edit-user screen I can upload the image for them as I want to have all my images same size on the member profile list page.

    I would really appreciate it if someone could now tell me how to incorporate shrink-image to one size into this plugin as a user could and will try to upload a 12×10 photo, etc… I’ve looked at WP shrink_dimensions code but don’t know exactly how to incorporate it.
    Thanks in advance.

  29. Does anyone know for WordPress MU, how you can display the 10 most recent profile pictures on the main page of the site? not the bloggers site, but the main site (ie:, not I want to have a “Newest Members” section on the main page, but can’t figure this out.

    Any help is appreciated.


  30. Mike: If you figure it out, I’d love to know, too. My first thought would be just a category called “Newest Members” with (regular WP) posts that you could customize with their photo, some info, etc. Of course, that’s probably not automated either … anyway, just a thought.

  31. I think if you have a space in the name of the file then that gives you an err. I just renamed my .jpg to a std 8.3 file name and it worked for me.

    I want to show a page where I can display the author photo and his ‘About yourself’ information. any help is greatly appreciated.


  32. Hi. My problem is that I can’t properly edit my /wp-admin/profile.php file. It’s only 20 lines long. If you can tell me where the edit I’m supposed to make belongs, I’ll be ready to go on to the next issue. For reference, the file looks like this:

    * User Profile Administration Panel.
    * @package WordPress
    * @subpackage Administration

    * This is a profile page.
    * @since unknown
    * @var bool
    define(‘IS_PROFILE_PAGE’, true);

    /** Load User Editing Page */

    (and thanks for your time. I’m sure the plugin is wonderful.)

    1. You will need to edit the file user-edit.php in line 182. When editing, keep your ‘action’ part blank so your line should look like this:

      <form id="your-profile" action="" method="post" enctype="multipart/form-data">
          1. There’s an issue with the current plugin that I use to post code in the comments. If you email the code to me, I can put it up manually. Sorry for the hassle.

  33. I’ve updated GiladG’s original comment with the code he sent me. I’ve also posted this other bit. Thanks for putting up with the situation until I can get it resolved!

    From GiladG:

    Another issue that I ran into with the plugin and was going to post a solution code was that when updating the profile page one must upload a picture each time because if no picture was included the update script would die saying ‘Please only upload jpg files!’. What I did to fix it was wrap the image processing portion with an IF so if a file was not uploaded the processing portion would be disregarded. So this is what it looks like now (blue is my addition (Editors note: just line one of the code)):

            if (is_uploaded_file($_FILES['photoUpload']['tmp_name'])) {
                if(($_FILES['photoUpload']['type'] == "image/jpeg") || ($_FILES['photoUpload']['type'] == "image/jpg")){
                        move_uploaded_file($_FILES['photoUpload']['tmp_name'], ABSPATH."/wp-content/images/".$userdata->user_login.".jpg");
                        //die("error: ".$_FILES['photoUpload']['error']);
                        die("<p><strong>Error:</strong> Please only upload jpg files! Your content type is <code>".$_FILES['photoUpload']['type']."</code></p><p>Please <a href='javascript:history.go(-1)' rel="nofollow">go back</a> and try again.</p>");

    Either way, you made my life a whole lot easier with this plugin. Never thought it would be so easy to implement the upload. Thank you for that!

    1. Thanks Andrew.

      Quick note, since the colors I had in my email do not show here, only the first line (IF STATEMENT) and the last line (CURLY BRACKET) are my addition. The rest is a part of the original code.

  34. site indexed in free

    Hey guys,

    Just looking to use this plugin. I had made the changes in my useredit.php file. But when i try to upload the photo it shows me the same error everytime.

    Can you please update me with the new code please.

  35. site indexed in free


    I had th problem i described in my last comment. The WP version – 2.8.6
    Plugin version – downloaded from above.

    My blog URL –

    Problem (once again) – Getting “Upload problem again and again”. I mean it says that Please upload .jpg photo. And shows a go back link.

    Do you have any more updated on thisplugin?

  36. A couple of notes –

    I’m using 2.9.1

    I had to edit line 125 instead of 182 in user-edit.php

    Also, I kept getting a weird error – content type is is pjpeg. Whatever that is? So I went ahead and edited fergcorp_addUserPhoto.php and made pjpeg instead jpeg an allowable content type.

    Then i had to add an images folder (CHMOD 777) in wp-content and now it seems to be working.

    Hope this helps for a future update.

  37. Hmm, no it’s not working actually. I see the image in my profile but it isn’t updating my past or future profile images in the comments sections.

  38. Great plugin.
    I got it to work no problem, but how can I output the user image?
    I tried the get_avatar, but no success to output the uploaded image.
    Any help will be appreciate. I am doing a site for a group who definitely are not using the avatar thing. The best change on getting their user image is trough an upload.

  39. I installed it and added the

    if (is_uploaded_file($_FILES['photoUpload']['tmp_name'])) {

    where appropriate in the fergcorp file. I can upload an image without receiving the error now.

    In the user-edit.php file @ line 182 I see this

    <input type="hidden" name="wp_http_referer" value="" />

    So before it I added this as you suggested

    I’m not sure if I did this correctly but I am positive I did the edit to fergcorp correctly because the it must be a .jpg error no longer appears. The issue now is that my image appears no where on my blog where I want it to show up for my user pic or avatar or whatever you want to call it. Can you help. view the user profile for mike.

  40. Hello,

    I followed the directions; however, I still can’t get it working. Does the plugin work in the latest version of wordpress?

    My wp-admin does not have a line 21 so I did not include that, but is there anything else that I am missing?

    When I upload it doesn’t upload anything, but it also does not give me an error.



Comments are closed.