Add Social info to WordPress Profiles

Just a quick for you all as I needed to do this recently for my AuthorBox on this site and I didn’t want to include a separate plugin to achieve this.

Just open up your functions. and add the below…


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Add contact links
function add_contactmethod( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    // Add Facebook
    $contactmethods['facebook'] = 'Facebook';
    // Add Facebook
    $contactmethods['googleplus'] = 'Google+';
    // Add Facebook
    $contactmethods['skype'] = 'Skype';
    // Remove Yahoo IM

    unset($contactmethods['yim']);
    unset($contactmethods['aim']);

    return $contactmethods;
}

add_filter('user_contactmethods','add_contactmethod',10,1);

I would class the above as pretty self explanatory if your used to but if not let me try and break it down for you.

We add a to

user_contactmethods

This lets us intercept the listed options before being processed. We get passed an which we store in $contactmethods

Array
(
    [aim] => AIM
    [yim] =>  IM
    [jabber] => Jabber /  Talk
)

From here we can just use normal PHP to create a new element to be stored. We could have used array_push() also but this way looks better to me. Try and keep the Key to one word or a hyphenated word, the value will be the text the end user sees.


1
2
// Add Twitter
$contactmethods[ KEY ] = VALUE;

Notice how I also some of the entries? These are just ones that I don’t feel I will need, you can either include these lines or not. Well I hope this helps you understand how to add your own custom details to the WordPress Profile pages. What’s that? You need to know how to get them back out aswell… ok then.

Retrieving Author information

Getting the new author meta information is really easy! Check out the official documentation on it afterwards here. If you are within the Loop then you can just use the below


1
2
3
// Get the Googleplus contact information
// This echo's out
the_author_meta( "googleplus");

Or if you need to use this somewhere else then just pass in the User ID along with the meta you want to get


1
2
3
// Get the Googleplus contact information
// This echo's out
the_author_meta( "googleplus", 21 //UserID );

Simple as that folks 😉