Add Social Media Links To WordPress User Profiles

In this WordPress tutorials you’ll see how easy it is to modify contact methods that are used for user profiles. You’ll also learn how to display these new fields within WordPress. This could be very useful for WordPress websites that allow anyone to register and display author information under their posts.

Remove unwanted contact methods

WordPress by default allows you to add Yahoo IM, AIM and Jabber fields in the WordPress user profile screen. The best way to remove these fields is to add the following WordPress filter hook to functions.php. WordPress filter hooks are used to modify the output of an existing WordPress function.

function remove_user_contact_methods( $contactmethods ) {
  unset( $contactmethods['yim'] );
  unset( $contactmethods['aim'] );
  unset( $contactmethods['jabber'] );

  return $contactmethods;
}
add_filter( 'user_contactmethods', 'remove_user_contact_methods' );

Add Social Media Links To User Profile

Add the following filter hook to functions.php to add the necessary fields to the user profile screen in WordPress.

function social_media_contact_methods($user_contactmethods){
  $user_contactmethods['twitter'] = 'Twitter Username';
  $user_contactmethods['facebook'] = 'Facebook Username';
  $user_contactmethods['linkedin'] = 'LinkedIn Profile';

  return $user_contactmethods;
}
add_filter('user_contactmethods', 'social_media_contact_methods');

Show Contact Methods After Your Posts

function wordpress_post_signature($content){
  if (is_single() && get_user_meta( $user_id, 'twitter', true) ):
    $content .= '<a href="http://www.twitter.com/' . get_user_meta( $user_id, 'twitter', true) . '" target="_blank" rel="external me">Follow ' . get_the_author() . ' on Twitter</a>';
  endif;
return $content; } add_filter("the_content", "wordpress_post_signature");

For more information on WordPress filter hooks please have a look at the WordPress add_filter codex.

Affiliate Disclosure:

We may link to products and online services provided by third-parties. Soe of the links that we post on our site are affiliate links, which means that we receive commission if you purchase the item. We will never recommend a product or service that we have not used ourselves. Our reviews will be honest and we will only recommend something if we have found it useful.

Disclaimer:

Lacey Tech Solutions publish blog articles to help small businesses. We are not liable for any damages if you choose to follow the advice from our blog.

Leave a Comment

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