May 06, 2013

May 06, 2013
2
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.

2 comments:

  1. The WordPress user profile screen allows you to set values for social services but some default services are irrelevant, namely AIM and Yahoo! IM; add to that the fact that Twitter and Facebook fields are missing.
    Web Development in Bangalore

    ReplyDelete
  2. Magento is leading e-commerce software platform mostly trusted. It also open source e-commerce web application. provides rich shopping experience.
    Web Designing Company in Bangalore | Web Design Companies Bangalore

    ReplyDelete