Social Links: How to Add in WordPress User Profile

The easiest way to add social links to WordPress user profile.

Social Links: How to Add in WordPress User Profile

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.

Like this post?

Get more stuff on WordPress design, development & business before they get published.

One Response to “Social Links: How to Add in WordPress User Profile”

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

Start a Conversation