Wordpress
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.
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.
PHP CMS Frameworks
May 06, 2013
Read more →
No more posts to load.
About this blog
PHPCMSFramework.com
Tutorials for WordPress, Laravel, Drupal, Joomla, Symfony & more — including AI-powered PHP guides. Publishing since 2012.
Trending posts
- Building a RAG System in Laravel from Scratch
- Steps to create a Contact Form in Symfony With SwiftMailer
- Build a WhatsApp AI Assistant Using Laravel, Twilio and OpenAI
- CIBB - Basic Forum With Codeigniter and Twitter Bootstrap
- Laravel and Prism PHP: The Modern Way to Work with AI Models
- Drupal 7 - Create your custom Hello World module
- Build an AI Code Review Bot with Laravel — Real-World Use Case
- Symfony Framework - Introduction
- Create Front End Component in Joomla - Step by step procedure
- A step by step procedure to develop wordpress plugin