WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to add avatars to my users. I have a limited group on a site I'm working. Uploading isn't really a problem we can just put the images on the server and use URL's to set our avatars(Only about 5 people will actually be able to post.). That said how would I add a field to the user page they can fill out with a image URL that can then be fetched later. I know you can fetch user data via the the_author_meta(); function but how do I add a custom user field that can them be filled out and put into the database that is the associated with the user?

Or would if just be better to use something that already exist like the aim field for example since none of us will be filling that out.

share|improve this question
up vote 1 down vote accepted

To add a field to the profile/user edit page you need to use the edit_user_profile hook and show_user_profile hook so:

add_action( 'show_user_profile', 'my_extra_user_fields' );
add_action( 'edit_user_profile', 'my_extra_user_fields' );
function my_extra_user_fields( $user ) 
{ ?>
    <h3>User avatar</h3>

    <table class="form-table">
            <th><label for="user_avatar">User avatar</label></th>
                <input id="user_avatar" name="user_avatar" type="text" value="
                    <?php $user_avatar = get_the_author_meta( 'user_avatar', $user->ID ); 
                        echo $user_avatar ? $user_avatar : '';?>" />
                <span class="description"><?php _e("Please enter Avatar URL."); ?></span>
<?php }

then to save that field you need to use personal_options_update hook and edit_user_profile_update hook so:

add_action( 'personal_options_update', 'save_my_extra_user_fields' );
add_action( 'edit_user_profile_update', 'save_my_extra_user_fields' );

function save_my_extra_user_fields( $user_id ) 
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }else{

        if(isset($_POST['user_avatar']) && $_POST['user_avatar'] != ""){
            update_usermeta( $user_id, 'user_avatar', $_POST['user_avatar'] );

and as you already know you can featch that data using the_author_meta() or get_user_meta()

share|improve this answer
Do these hooks fit anywhere within the user file? Since it has the html markup and all I assume it can just fit into any place I find fitting so that it list in the proper location in the page with the other fields. – New_Wav Jul 13 '11 at 21:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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