Free Wordpress Blog Setup

How to Display Author’s Twitter and Facebook on the Profile Page

By Editorial Staff in Tutorials
How to Display Author’s Twitter and Facebook on the Profile Page

By default WordPress allow to display author’s website, email, and a few other useless IM contacts, but it is missing important social media networks like Facebook, and Twitter. In this tutorial, we will show you how you can add author’s twitter, facebook, linkedin, or any other contact info on the profile page.

First thing you need to do is open your functions.php in your template folder and add the following codes:

<?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);
?>

You can follow the methods and add any other field that you want. Once you add this function, user profile page in the admin panel will look like this:

Extend User Contact Info

Add the information there. Now you will need to display it in your template through author.php file. You should check out our tutorial on How to Add an Author Profile Page in WordPress and for further documentation also look at WordPress Codex page for Author Templating.

All you have to do is paste the following code in your template file:

<?php echo $curauth->twitter; ?>

You can change the name of the field to what you like. This way you can display it in your author.php file. You may modify it to your liking. For example use this as links and so on.

For example, if your value is simply “wpbeginner” in that field. Then you can paste this code in your author.php

<a href="http://twitter.com/<?php echo $curauth->twitter; ?>" target="_blank"><?php echo $curauth->twitter; ?></a>

If you have any questions feel free to write it in the comments, and we will answer them.

Note: This tutorial will work in WP 2.9+ thanks to Joost De Valk

Free Wordpress Blog Setup

Comments

9 Responses to “How to Display Author’s Twitter and Facebook on the Profile Page”
  1. very cool. i’m using it.

  2. Luke says:

    Thank you for this.

    Stupid question: What’s the code if you want to show only the info that’s displayed in user profile.

    For example, when I add these in the user profile and don’t enter data, it still shows the icon.

  3. Enk. says:

    A little more in details, how can we get it working like we only write ‘wpbeginner’ in fields and it links automatically ?

  4. rayne says:

    How do I add a dropdown instead of a text field?

  5. Scott Lewis says:

    I added the code that you suggest at the end of my functions.php and it added the 2 lines into my profile. The only thing is that every time I update anything, I get the white page of death. If I go back to the previous page, the update was successful. It just won’t bring me directly back to the page I just updated. I had to take out the code because it was too much of a PITA.

    Any ideas what I did?

Share Your Opinions

Tell us what you're thinking...
and if you want a pic to show with your comment, then get gravatar!

Please make sure that you have read our Comment Policy.

Due to high volume of request from our readers, we are adding this feature that allows you to stay updated with this post's comments without having to participate in the discussion even though we would love your input as always. Don't worry we hate SPAM just as much as you do, so you will never receive any SPAM messages from our site and that's our promise to you.

Subscribe without commenting

Close Bar