How to Add Custom User Contact Info in WordPress

Since the time of this post, WordPress has finally added support for Google+, Twitter and Facebook.

However, they still do not support LinkedIn, and they still have some old fields displayed, so I will simply use this tutorial to show you how to add a LinkedIn field (and remove legacy fields) and then display it on your site.

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 of your WordPress theme:

add_filter( 'user_contactmethods', 'tgm_io_custom_contact_info' );
/**
 * Removes legacy contact fields and adds support for LinkedIn.
 *
 * @param array $fields  Array of default contact fields.
 * @return array $fields Amended array of contact fields.
 */
function tgm_io_custom_contact_info( $fields ) {
	
	// Remove the old, unused fields.
	unset( $fields['aim'] );
	unset( $fields['yim'] );
	unset( $fields['jabber'] );
	
	// Add LinkedIn.
	$fields['linkedin'] = __( 'LinkedIn' );
	
	// Return the amended contact fields.
	return $fields;
	
}

The code above removes the legacy AIM, Yahoo and Jabber fields and adds in a LinkedIn profile field.

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 the new LinkedIn field by using this PHP command:

<?php the_author_meta( 'linkedin', get_current_user_id ); ?>

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

Enjoy? See Inside my WordPress Toolbox

Over 20,000 people have purchased my WordPress products. Get absolutely FREE access to regular updates and my toolbox - a collection of WordPress-related products and resources that every WordPress professional should own.