Quick Tip: Add Extra Contact Methods to User Profiles
If you Google “add extra fields to WordPress user profile” you’ll find all sorts of involved coding examples for adding extra inputs to the user profile page so you can capture additional user information. But if all you want to do is expand the default contact methods section then there’s a much simpler way to go.
The user_contactmethods Filter
The user_contactmethods filter allows you to set and unset the contact info fields on the user profile page. The great thing about using this method is that WordPress looks after the creation and updating of the fields.
Let’s add fields for Twitter and Facebook info. Put this in your functions.php file:
add_filter('user_contactmethods', 'my_user_contactmethods');
function my_user_contactmethods($user_contactmethods){
$user_contactmethods['twitter'] = 'Twitter Username';
$user_contactmethods['facebook'] = 'Facebook Username';
return $user_contactmethods;
}
Here is what you’ll get:

If you want to remove some fields, just unset them from the array:
function my_user_contactmethods($user_contactmethods){
unset($user_contactmethods['yim']);
unset($user_contactmethods['aim']);
unset($user_contactmethods['jabber']);
$user_contactmethods['twitter'] = 'Twitter Username';
$user_contactmethods['facebook'] = 'Facebook Username';
return $user_contactmethods;
}

To display the user’s info, simply use the get_user_meta function.
echo get_user_meta(1, 'twitter', true);
This will show the Twitter username for the user with an ID of 1. The true argument causes the data to be returned as a single value as opposed to an array.
That’s all there is to it!


Nice Info. Thanks
This is insane… I was just going to continue on a project where I needed to do this exact stuff and you post a tutorial about that – and this is not the first time this happens. I dont know how you do it – but just continue with that : D
Glad we could help!
Great tutorial! I can think of so many applications for this.
Any thoughts if it’s possible to add a photo upload function for the user as well?
Just use the User Photo plugin. Or disect it to see how it’s dealing with the process and replicate it.
Good idea. Any thoughts on how to add to the “About Yourself” section?
Don, check the WordPress codex for Settings API. You can use that to add new fields to existing options pages. You should even be able to specifically target the About Yourself section.
Ha, just did this two days ago for a client. Couldn’t believe how simple it was.
You can also easily add those fields to WordPress registration page, so users can enter this custom info while registering by doing something like this:
Twitter
<input id="twitter" class="input" type="text" tabindex="60" size="25" value="” name=”twitter” />
Not tested in this form (and I hope I posted it so the code shows correctly) because I butchered it a little bit to only show one field, but it should work.
Using this, I guess you could integrate with Twitter to send an automated tweet from your site’s Twitter when a new user registers:
“@TwitterUsername has just registered for SuperWebsite.com…”
Although you’d probably need to add a checkbox to let users know a tweet will be sent out, and let them disable it. I’m getting carried away
Looks like code didn’t go through, here it is – http://pastebin.com/nzReBnVw
Nice and easy!
Strange… it didn’t work for me? I added it as the last filter/function in my functions.php file. I don’t know what I’m doing wrong. I copied and pasted it exactly the same as is printed above:
add_filter(‘user_contactmethods’, ‘my_user_contactmethods’);
function my_user_contactmethods($user_contactmethods){
$user_contactmethods['twitter'] = ‘Twitter Username’;
$user_contactmethods['facebook'] = ‘Facebook Username’;
return $user_contactmethods;
}
Shane, the code works fine. I’ve just done the copy and paste into my functions file to double-check, and it’s working as expected.
Great tip!
Hey Ross,
This really is a great tip, did this just a few days ago, lot of people would find this extremely useful…
I have a little question. I want to add a “Contact Number” field in the registration page as well as in the user profile page. Could anyone give a suggestion as to how to do it. I have already used Cimy Extra User Field plugin, looking for something else though!!