AddandRemoveProfileFieldstoWordPressUser? Fo

Source: Internet
Author: User
Thewordpressuserprofilescreenallowsyoutosetvaluesforsocialservicesbutsomedefaservicservicesareirrelevant, namelyAIMandYahoo! IM ;? AddtothatthefactthatTwitterandFacebookfieldsaremissing .? Youquicklyrealizetha

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 .? You quickly realize tha

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 .? You quickly realize that the default form... Needs work .? WordPress provides a method for adding and removing profile fields .? Let me show you how it works!

Filter Setup

The first step is creating a function in your functions. php file which will 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 provides access to that important protected array .? The returned value becomes the list of user profile fields.

Adding a Profile Field

Adding a new field, Twitter handle for example, using des 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');

Simply adding that key/value to the array adds a new field to the form.

Removing a Profile Field

Conversely, 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 fieldsunset($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.

Retrieving Custom Field Values

To retrieve custom field values, use? Get_the_author_meta method:

// Retrieve a custom field value$twitterHandle = get_the_author_meta('twitter');

The ability to easily add profile form fields is awesome ;? Super easy to do, no plugin required!

Read the full article at: Add and Remove Profile Fields to WordPress User Form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.