Grow your CSS skills. Land your dream job.

Last updated on:

Add/remove contact info fields

User profiles in WordPress by default have these fields for Contact Info by default: E-mail, Website, AIM, Yahoo IM, Jabber / Google Talk. You can remove those and add new ones as you wish, like in this example code for your functions.php file in your theme:

function new_contactmethods( $contactmethods ) {
   $contactmethods['twitter'] = 'Twitter'; // Add Twitter
   $contactmethods['facebook'] = 'Facebook'; // Add Facebook
   unset($contactmethods['yim']); // Remove YIM
   unset($contactmethods['aim']); // Remove AIM
   unset($contactmethods['jabber']); // Remove Jabber

   return $contactmethods;
}

To display that publicly, you could:

$user_id = 1;
$key = 'twitter';
$single = true;

$user_twitter = get_user_meta( $user_id, $key, $single); 

echo $user_twitter; 

Reference URL

Comments

  1. Hassan
    Permalink to comment#

    Missed a line! Without defining the filter, the function itself won’t do anything!

    add_filter('user_contactmethods','new_contactmethods',10,1);
  2. Really like this, and glad I’ve found it! Definitely going to use it on my WordPress installs.

  3. Awesome. Didn’t know this, thank you.

  4. OneWorld
    Permalink to comment#

    Removing just works for those three: AIM, YIM, Jabber ;(

  5. Permalink to comment#

    unset ($ contactmethods ['url']) does not remove

Leave a Comment

Current day month ye@r *

*May or may not contain any actual "CSS" or "Tricks".