How To Add And Remove User Contact Fields In WordPress

WordPress comes with its own default set of user contact fields in profiles, which are: AIM, Yahoo IM and Jabber / Google Talk, instead of what we really use. Nobody in this world got time to create a Jabber or AIM account. Most of users want Facebook, Twitter and Google + fields in WordPress.

Since the 2.9 release, WordPress allows us to add or remove custom contact fields to your website with some simple codes. The example code below adds Twitter and removes Yahoo IM:

function add_twitter_contactmethod( $contactmethods ) {
  // Add Twitter
  if ( !isset( $contactmethods['twitter'] ) )
    $contactmethods['twitter'] = 'Twitter';

  // Remove Yahoo IM
  if ( isset( $contactmethods['yim'] ) )
    unset( $contactmethods['yim'] );

  return $contactmethods;
}
add_filter( 'user_contactmethods', 'add_twitter_contactmethod', 10, 1 );

Easy, right? You can also easily retrieve the custom field info with following snippet:

if ( is_singular() ) {
  global $post;
  $twitter = get_the_author_meta( 'twitter', $post->post_author );
}

Now, you can add and remove user contact fields in your or your client’s WordPress website. You can do this in your theme’s functions.php or in a plugin.

If you found this post useful, share it with your friends:

Leave a Reply