Add/Remove Profile Fields in WordPress User Form - Step by Step tutorial

In this article, we are going to discuss about, How to add/remove the new additional profile fields in the WordPress User Form. In this article, I am going to explain about "How to add the Twitter, Facebook and Google Plus profile fields in the WordPress User Form. WordPress provides a method for adding and removing profile fields.

To do the above process, no need to add the additional new plugins.

Step 1 : Filter Setup

Creating new function called "modify_contact_methods" in functions.php file which accept an array of profile keys and values.

function modify_contact_methods($profile_fields) 
{
// Field addition and removal will be done here
}
add_filter('user_contactmethods', 'modify_contact_methods');

This function returns the list of user profile fields.


Step 2 : Adding a New Profile Field

Adding a new field, Twitter handle for example, includes adding a key to the passed in array, with a value which will act as the field label:

function modify_contact_methods($profile_fields) 
{
// Add new fields
$profile_fields['twitter'] = 'Twitter Username';
$profile_fields['facebook'] = 'Facebook URL';
$profile_fields['gplus'] = 'Google+ URL';
return $profile_fields;
}
add_filter('user_contactmethods', 'modify_contact_methods');


Step 3 : Removing a Profile Field

Removing a key from said array removes a field from the user profile form:

function modify_contact_methods($profile_fields) 
{
// Add new fields
$profile_fields['twitter'] = 'Twitter Username';
$profile_fields['facebook'] = 'Facebook URL';
$profile_fields['gplus'] = 'Google+ URL';
// Remove old fields
unset($profile_fields['aim']);
return $profile_fields;
}
add_filter('user_contactmethods', 'modify_contact_methods');

The code above removes the AIM field from the edit profile form.