Extend the User Contact Info in WordPress 2.9

WordPress-Christmas-16
Joost de Valk wrote about a month ago a really great article about his idea, to expand the user contact fields (thanks Joost!). In version 2.9 you are able to use this possibility. Here a little example, how you can use this functionality.

First you write your own function in your functions.php of your theme.

<?php
function my_new_contactmethods( $contactmethods ) {
  // Add Twitter
  $contactmethods['twitter'] = 'Twitter';
  //add Facebook
  $contactmethods['facebook'] = 'Facebook';

  return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
?>

This function does nothing more than expand the array $contactmethods with the fields twitter and facebook. The value behind the fields is used as a label for the input fields. You can also remove existing fields, here the field of YAHOO IM:

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

WordPress contact info edit screen

This fields can be displayed on the author page.

<?php
$current_author = get_userdata(get_query_var('author'));
?>
<p><a href="<?php echo esc_url($current_author->twitter);?>" title="Twitter"> Follow me on Twitter</a></p>

Alternatively you can also use the template tag the_author_meta.

the_author_meta('facebook', $current_author->ID)

That's all behind the 16ht door of our Advent Calendar. :) Have fun expanding your contact fields.

16 Comments
  1. says:

    Very usefull ! Thanks guys...

  2. sebastien says:

    wp2.9, it's for when ?

  3. Matt B says:

    Well done! I somehow managed to miss the fact that this is for 2.9, not 2.8.6. Small detail, but this looks well worth the improvement.

    Keep it up!

  4. Don says:

    This is great, I've been wondering if this was possible because I've been put in charge of the server for a clan's website, and adding more contact fields (like tag, and other things) is really nice.

    The downside of this is that I'll have to wait until 2.9 is released in final because I really don't want to upgrade them to a beta release...

  5. Dieter says:

    Thanks for this useful hint.
    As user of Twitter I´m especially interested in the enhancement with the link to the Twitter account.
    And folks: WP 2.9 is out now! :-)

  6. Jones Lee says:

    Nice feature, do you know what function to add extra userdata so I could use it with wp_insert_user to add in more fields like Country, Address, etc

  7. Really nice easy way to showcase how to extend the author contact information, I think WordPress should include "Twitter/Facebook" by default now.

  8. Konstantin says:

    Awesome! I hated how I had to hardcode everything. I'll definitely use that in my current project.

  9. Ryan says:

    Fantastic article, I have been searching for a few days on how to do this.

    Now, I am using this combined with "Members List" to show users details.

    Thanks!

  10. Ryan says:

    This is awesome, thanks so much for sharing.

    I use this in conjunction with:
    http://bavotasan.com/tutorials/how-to-display-an-author-list-with-avatars-in-wordpress/

    To extend my user info, and I show it on whatever pages I want by using conditional statements in my sidebar.

    Thanks again!

  11. Mindaugas says:

    great tips, but displaying custom field not working, it returns blank value

  12. Sina Saeedi says:

    How can I do that if I want to add "Phone Number" and "Birth Date" fields to registration page?

  13. Michael says:

    Here is a nice article how to do that: http://planetozh.com/blog/2009/12/how-to-per-user-options-in-wordpress/
    Change it to your needs.

  14. Frank says:

    What if someone does not include the "http://" in the url they submit (with their twitter or facebook url).

    I'll get something like this -> http://www.mywebsite.com/www.twitter.com/myname when i click their url on the authorpage.

    Is there an option to automatically include the "http://" ?

  15. Frank says:

    Oh i got it already

    echo esc_url (does the trick)

    sorry ;-)

  16. Frank says:

    I thought i got the solution but it's still not working. esc_url only displays the http:// on the authorpage. But the link is still referring to http://www.mywebsite.com/www.twitter.com/myname ;-(

4 Pings
  1. User Conatct Info in WordPress 2.9 erweitern - Twitter, Facebook, add_filter, Benutzerprofil - dynamicinternet
  2. 37 Cool Wordpress Hacks And Tutorials You Should Try |
  3. Twitter @Anywhere in WordPress Comments Tutorial
  4. WPEngineer gears up for their own WordPress Advent Calendar | WPCandy