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_contactmethods( $contactmethods ) {
unset( $contactmethods['yim'] );
unset( $contactmethods['aim'] );
unset( $contactmethods['jabber'] );
return $contactmethods;
}
add_filter( 'user_contactmethods', 'remove_user_contactmethods' );
Add social media contact methods
Add the following filter hook to functions.php to add the necessary fields to the user profile screen in WordPress.
function social_media_contactmethods($user_contactmethods){
$user_contactmethods['twitter'] = 'Twitter Username';
$user_contactmethods['facebook'] = 'Facebook Username';
$user_contactmethods['googleplus'] = 'Google+ Profile';
return $user_contactmethods;
}
add_filter('user_contactmethods', 'social_media_contactmethods');
Show these contact methods after your posts
In an earlier post I discussed how you would add content after WordPress posts, as an extension of that I’ll show you how to add these social media contact methods after your posts.
function wordpress_post_signature($content){
if (is_single()){
if( 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>';
}
}
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.


