By default, WordPress includes only three social links for a user profile. But a good thing is that WordPress provides a handy filter to modify user contact fields.

Add Social Links to WordPress User Profile

Use the below code to add and modify user contact fields. You can add the code in functions.php of your active theme or you can add it to a plugin file.

/**
 * Adds social links to user profile
 *
 * @param $user_contact
 * @return mixed
 */
function thewebsitedev_user_social_links( $user_contact ) {
   /* Add user contact methods */
   $user_contact['facebook'] = __('Facebook Link', 'topaz');
   $user_contact['twitter'] = __('Twitter Link', 'topaz');
   $user_contact['dribbble'] = __('Dribbble Link', 'topaz');
   $user_contact['pinterest'] = __('Pinterest Link', 'topaz');
   $user_contact['linkedin'] = __('LinkedIn Link', 'topaz');
   $user_contact['googleplus'] = __('Google+ Link', 'topaz');

   return $user_contact;
}
add_filter('user_contactmethods', 'thewebsitedev_user_social_links');

Remove Social Links from WordPress User Profile

You can also remove contact fields using this method. Below is an example of how to remove contact fields from a user profile in WordPress:

/**
 * Adds social links to user profile
 *
 * @param $user_contact
 * @return mixed
 */
function thewebsitedev_user_social_links( $user_contact ) {
   /* Remove user contact methods */
   unset( $user_contact['facebook'] );
   unset( $user_contact['twitter'] );
   unset( $user_contact['googleplus'] );

   return $user_contact;
}
add_filter('user_contactmethods', 'thewebsitedev_user_social_links');

Display Social Links from WordPress User Profile

We just need to make sure that we display social link only if it is not empty. Below is an example code to display social links:

// Display social links
<?php if(!empty(get_the_author_meta('facebook'))) { ?>
 <a href="<?php the_author_meta('facebook'); ?>" title="Facebook" target="_blank" id="facebook"><img src="/images/facebook.png" alt="Facebook" /></a>
<?php } ?>

You can read more about the user_contactmethods filter here.

Do you like Gautam Thapar's articles? Follow on social!
People reacted to this story.
Show comments Hide comments
Comments to: Social Links: How to Add in WordPress User Profile
  • March 29, 2018

    Hi very nice article keep it up the good work Wonderful!! Thank you for posting informative blog. Your posts are more interesting and informative

    Reply
Write a response

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Login

Welcome to Typer

Brief and amiable onboarding is the first thing a new user sees in the theme.
Join Typer