Easily Extended Contact Info in WordPress

I’m working on a project where I need the ability to add “Phone”, “Building”, and “Room” as information a user could add in their profile. I also wanted to remove “AIM”, “Yahoo”, and “Jabber” — none of the users are going to need to fill in that info.

You can easily add this code into your functions.php. I was writing it for a WordPress MU site with multiple themes and needed to make sure it was enforced, so I stuck it in the mu-plugins directory, in a file named “extended-contact-info.php”.

This is the simple code block you need:

function extended_contact_info($user_contactmethods) {
	//Use this if you want to append to the default 
	//contact methods (AIM, Yahoo, Jabber)
	//$user_contactmethods += array(
	//	'building' => __('Building'),
	//	'room' => __('Room'),
	//	'phone' => __('Phone')
	//);

	//Use this if you want to ignore the default 
	//contact methods (AIM, Yahoo, Jabber)
	$user_contactmethods = array(
		'building' => __('Building'),
		'room' => __('Room'),
		'phone' => __('Phone')
	);
	
	return $user_contactmethods;
}

add_filter('user_contactmethods', 'extended_contact_info');

Leave a Reply