64x64 icon dark hosting
Choose a hosting plan here and get a free year's subscription to Tuts+ (worth $180).

Quick Tip: Add Extra Contact Methods to User Profiles


Start a hosting plan from $3.92/mo and get a free year on Tuts+ (normally $180)

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:

Here is what you'll get:

If you want to remove some fields, just unset them from the array:

To display the user's info, simply use the get_user_meta function.

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!