Add and Remove Contact Methods

WordPress profiles include fields for contact methods, many of which aren’t used very often. It’s a legacy of early versions of WordPress. But the list is easily filterable, so we can change them to more useful fields.

This function lets you specify an array of contact methods you’d like removed, and those you’d like to add.

You can access your new contact methods in theme files like this: get_the_author_meta( 'linkedin' );

<?php
/**
* Update Contact Methods
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/add-remove-contact-methods/
*/
function be_contact_methods( $contactmethods ) {
$remove = array( 'aim', 'yim', 'jabber' );
foreach( $remove as $service ) {
if( isset( $contactmethods[$service] ) ) {
unset( $contactmethods[$service]);
}
}
$add = array(
array(
'service' => 'linkedin',
'label' => 'LinkedIn URL',
),
array(
'service' => 'netvibes',
'label' => 'Netvibes URL',
),
array(
'service' => 'twitter',
'label' => 'Twitter URL'
),
);
foreach( $add as $item ) {
if( !isset( $contactmethods[$item['service']] ) ) {
$contactmethods[$item['service']] = $item['label'];
}
}
return $contactmethods;
}
add_filter( 'user_contactmethods', 'be_contact_methods' );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk