Soliloquy - The Best Responsive WordPress Slider Plugin

How to Add Custom User Contact Info in WordPress

Share This Post

If there is one thing that I do not like about WordPress, it is the fact that it gives outdated options for user contact information. AIM? Yahoo? The internet has steadily moved away from these to things like Facebook and Twitter. After some digging around in the core files of WordPress and hunting on the internet, I’ve found a way to add custom user contact information fields in the ‘Users’ section of WordPress through the functions.php file (or custom_functions.php file if you use Thesis).

Let’s get started with our tutorial!

Setting Up the Function

The awesome thing about this tutorial is that we don’t need to mess with any of the core files in order to make this work. All we need to do is write our own function that determines the contact information input fields for our users.

Copy and paste the following code into your functions.php or custom_functions.php file:

[php]/* BEGIN Custom User Contact Info */
function extra_contact_info($contactmethods) {
$contactmethods['facebook'] = ‘Facebook’;
$contactmethods['twitter'] = ‘Twitter’;
$contactmethods['linkedin'] = ‘LinkedIn’;
return $contactmethods;
add_filter(‘user_contactmethods’, ‘extra_contact_info’);
/* END Custom User Contact Info */[/php]

Breaking Down the Code

Basically what is happening here is we are creating a new function called extra_contact_info and applying it as a filter to $user_contactmethods. You can learn more about $user_contactmethods by going to your wp-includes/registration.php file and scrolling to the very bottom to see the code for it.

Within this function we are adding some filters. The first set of filters is applying the unset rule, which essentially destroys (unsets) a previously set variable. What this means for you is that it causes WordPress to remove the default user contact information fields of “AIM”, “Yahoo”, and “Jabber/Google Talk”. If you would like to retain one or more of these fields, simply remove the line that references one of these three things.

The next set of filters creates new user contact information fields for us to use. In this example, I’ve created new fields that can be used for Facebook, Twitter and LinkedIn. All we are telling WordPress to do is register these new input fields for us.

Finally, we use add_filter in order to apply our changes.

How to Add Custom User Contact Info in WordPressSave your file and go to the “Edit” portion of your own user. You will notice that you have awesome new contact information fields that are actually relevant to your users! You can view an example of what it should look like in the image to our left.

Making Use of Our New Contact Fields

Making use of these fields is just as simple as displaying the author’s name, URL and number of posts he/she has made. We just apply a little PHP and bam, our user contact info is in use.

You can call any of these fields by using this PHP command:

[php]<a href="<?php the_author_meta(‘facebook’, $current_author->ID); ?>"></a>[/php]

This creates a link to whatever URL your user entered in the “Facebook” contact field. Simply swap out ‘facebook’ for any other field that you defined in your function (for this example, ‘twitter’ or ‘linkedin’) in order to display that particular URL information.

Customizing your users contact information inputs is especially useful for post author boxes.
Now you have the option of easily setting up Facebook and Twitter links for your guest posts.

Enjoy and let me know if you have any questions on how to get things done!

Have you enjoyed reading How to Add Custom User Contact Info in WordPress? Sign up below to get regular content updates and also get my "7 Tips to a Professional WordPress Setup" absolutely free!

About Thomas Griffin

I live and breathe WordPress. I create products around WordPress (Soliloquy and OptinMonster), contribute to WordPress core and do lots of fun development around WordPress in general. You can find me on Twitter, Facebook and Google+.