Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been advised how to add additional contact info fields to the User admin area here (Click here).

However, I am not entirely sure how I can display the the field contents in a link within my template files.

Here is the code in my functions.php:

add_filter( 'user_contactmethods', 'more_contactmethods' );
function more_contactmethods( $contactmethods ) {
    $contactmethods['twitter'] = 'Twitter URL';
    $contactmethods['facebook'] = 'Facebook URL';
    $contactmethods['linkedin'] = 'LinkedIn URL';
    return $contactmethods;
}

And here's the code in one of my template files, but it doesn't seem to work, so I wonder whether I can actually do it this way?

<?php 
    $twitter = get_usermeta( $user_id, 'facebook' ); 
    $facebook = get_usermeta( $user_id, 'twitter' );
    $linkedin = get_usermeta( $user_id, 'linkedin' );
?>

    <a href="<?php echo $twitter ?>" id="twitterBtn" title="Visit our Twitter page">Visit our Twitter page</a>
share|improve this question
    
get_usermeta has been depreciated and replaced with get_user_meta. Also can you verify $user_id has a value? –  v0idless Oct 31 '11 at 14:56
    
I'm actually a bit confused by this now...sure there is a value for $user_id? Also, why wouldn't <?php echo ($contactmethods['twitter']) ?> work? –  remi90 Oct 31 '11 at 15:36
    
The $contactmethods array is only available when you use the user_contactmethods filter. To access the user metadata, you need to use the get_user_meta function. Can you actually verify the data is getting into the database? You may need to hook personal_options_update and edit_user_profile_update to actually save the data. –  v0idless Oct 31 '11 at 16:14
    
What does a <?php var_dump( get_user_meta( $user_id, 'user_contactmethods' ) ); ?> return? –  Chip Bennett Oct 31 '11 at 20:43

2 Answers 2

up vote 1 down vote accepted

This might help you out if you haven't found an answer yet.

/* BEGIN Custom User Contact Info */
 function extra_contact_info($contactmethods) {
     unset($contactmethods['aim']);
     unset($contactmethods['yim']);
     unset($contactmethods['jabber']);
     $contactmethods['facebook'] = 'Facebook';
     $contactmethods['twitter'] = 'Twitter';
     $contactmethods['linkedin'] = 'LinkedIn';
     return $contactmethods;
 }
 add_filter('user_contactmethods', 'extra_contact_info');
 /* END Custom User Contact Info */

Displaying it:

<a href="<?php the_author_meta('facebook', $current_author->ID); ?>"></a>

http://thomasgriffinmedia.com/blog/2010/09/how-to-add-custom-user-contact-info-in-wordpress/

share|improve this answer
// Add/Remove Contact Methods
function add_remove_contactmethods( $contactmethods ) {
    $contactmethods['twitter'] = 'Twitter';
    $contactmethods['facebook'] = 'Facebook';
    $contactmethods['Youtube'] = 'YouTube';
    $contactmethods['linkedin'] = 'LinkedIn';
        $contactmethods['skype'] = 'Skype';
    // Remove Contact Methods
    unset($contactmethods['aim']);
    unset($contactmethods['yim']);
    return $contactmethods;
}
add_filter('user_contactmethods','add_remove_contactmethods',10,1);

This works fine in Thesis. Here's the full tutorial

http://wpsites.net/how-to-wordpress/how-to-addremove-custom-user-profile-contact-info-links-to-your-author-box/

share|improve this answer
    
Thanks @BradDalton, I think I'm having trouble with the code to actually echo the value though. Can you help with this? –  remi90 Oct 31 '11 at 20:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.