How to Add Contact Methods for Twitter, Facebook, and Flickr to Your WordPress Profile

Home » Snippets » How to Add Contact Methods for Twitter, Facebook, and Flickr to Your WordPress Profile
0

Created with:

Visibility: 

public

Creator: Alex

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Social media has become an integral part of our daily lives, and it’s no surprise that it’s also become increasingly important in the professional world. As a WordPress user, you have the ability to add your social media accounts to your profile, making it easy for others to connect with you on various platforms. In this article, we’ll show you how to add contact methods for Twitter, Facebook, and Flickr to your WordPress profile.

					function WPTurbo_add_contact_methods( $user_contactmethods ) {

	$user_contactmethods['twitter'] = esc_html__( 'Twitter Username', 'wpturbo' );
	$user_contactmethods['facebook'] = esc_html__( 'Facebook URL', 'wpturbo' );
	$user_contactmethods['flickr'] = esc_html__( 'Flickr Username', 'wpturbo' );

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

This code snippet adds new contact fields to user profiles in WordPress. In particular, it adds fields for Twitter username, Facebook URL, and Flickr username. When this code is run, the user_contactmethods filter hook is called with the WPTurbo_add_contact_methods() function.

The function accepts a single parameter, which represents the existing contact methods. Within the function, we add new keys to the $user_contactmethods array using the square bracket notation. The key indicates the unique identifier of the contact method, and the value specifies the label for the field.

We use the WordPress esc_html__() function to escape and translate the label strings.

$user_contactmethods['twitter'] = esc_html__( 'Twitter Username', 'wpturbo' );
$user_contactmethods['facebook'] = esc_html__( 'Facebook URL', 'wpturbo' );
$user_contactmethods['flickr'] = esc_html__( 'Flickr Username', 'wpturbo' );

Finally, the updated array is returned by the function to update the contact methods.

return $user_contactmethods;

And the function is hooked to the user_contactmethods filter with the add_filter() method. Once hooked, the modified list of user contact methods will be rendered on the user profile page.

add_filter( 'user_contactmethods', 'WPTurbo_add_contact_methods' );

That’s it. You can use this code snippet in your plugin or theme to allow users to provide additional contact information to their WordPress user profiles.

Register an account to save your snippets or go Pro to get more features.