Add and Remove Profile Fields to WordPress User Form

By on  

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, 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');

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 fields

	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 the 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!

Track.js Error Reporting

Recent Features

  • 9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

  • 5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • Smooth Scrolling with MooTools Fx.SmoothScroll

    I get quite a few support requests for my previous MooTools SmoothScroll article and the issue usually boils down to the fact that SmoothScroll has become Fx.SmoothScroll. Here's a simple usage of Fx.SmoothScroll. The HTML The only HTML requirement for Fx.SmoothScroll is that all named...

  • Image Reflections with CSS

    Image reflection is a great way to subtly spice up an image.  The first method of creating these reflections was baking them right into the images themselves.  Within the past few years, we've introduced JavaScript strategies and CANVAS alternatives to achieve image reflections without...


  1. If only I saw this a few weeks ago. A great tip. Will be useful to most everybody till the WordPress devs finally take to updating that profile fields.

  2. Adrian

    Simple and helpful, thank you!

    Still, if you’re not a developer comfortable with writing code, Profile Builder (http://wordpress.org/extend/plugins/profile-builder/) may come in handy. Besides adding extra user fields it provides shortcodes for front-end login, register and edit profile forms.

  3. Amit

    I want to create a custom search filter like Date and some custom field for Post.
    can you please help me. how can i manage this on Post Listing Page.

  4. Is there a good way to retrieve all of the added fields in an array and assign them to variables?

  5. I can see immediate use of this, when using the portfolio themes. A CSS designed block and the profile field can be used for the portfolio page. Thanks David, this is giving me a lot of ideas on usage of the fields. :)

  6. tim

    good thing there are others with briliant minds.

    I need to ask you how can i make another page for user profile diferent from the one wordpress gives and how can i add a field for user image.

  7. I am working on a multi-site plugin and this will come handy. Thanks. But is there a simple way to add multiline text field?

  8. THANK YOU! So elegant. Worked perfect.

  9. How about if I want to add fields to a different section other than the contact area? Is this a similar process?

  10. hand-coding

    Hi David, great post.
    How could we store those values in the db as an array instead of separate fields ?

  11. hand-coding

    Just o be clear:
    I’d love to see extra infos displayed as separate fields but stored in a single associative array…

  12. Pat

    Thanks for the post, man! Great stuff!

  13. this was actually informative – not like most of what i see online. sharing :)

  14. I was exactly looking for “Retrieving Custom Field Values”, and finally got it here. Thank you very much.

  15. Thanks man! That helped out a lot!

  16. Liz

    I get a warning message when I hit Update Profile after adding my Google+ url.

    Warning: Cannot modify header information – headers already sent by (output started at themes/selectitaly/functions.php:15) in wp-includes/pluggable.php on line 875.

  17. Surya

    How can I add a custom field in “Add new user” fields

  18. Tieson Wooten

    Thanks for the info, just what I was looking for!

  19. In profile builder I am unable to find how to change profile fields.

  20. thanks for the post.
    I also like the justin tadlock’s method -http://justintadlock.com/archives/2009/09/10/adding-and-using-custom-user-profile-fields

  21. Maya

    Awesome, thanks!!!

  22. jos

    Is it possible to rename the existing filename like AIM to ‘ street name’

  23. I does involve writing code but there is a cool plugin http://piklist.com/ that is in beta allows you to use the additional fields anyplace you want in WordPress http://piklist.com/ . Check it out (I just use it. I am not related to the development in any way)

  24. Ulfstein

    Is there an easy way to set this up so that the changes made to function.php get carried over through a WordPress update?

    Many thanks.

  25. i wanted to show the profile picture in the dashbord

  26. Has anyone had trouble getting this code to work in WP 3.8.1? The code has been added to my client’s functions.php file and I’m not seeing any results.

    I’m looking for the additional field on the “Edit User” page, but not seeing it added. Thoughts? Has the hook changed in WP core?

    Thanks for this workaround — I’d love to have it working on our end.

  27. Chris

    Hello, thanks for the post. It works awesome but I’m having a single issue. I get no links for these social fields. I see something like http://www.example.com with no posibility of clicking whatsoever. Am I doing anything wrong ?

  28. Mike Levine

    You have no idea how appreciative I am to have found this post. Seriously, thank you from the bottom of my heart for such a helpful and clear explanation of these items.

  29. Thanks a lot. I didn’t thought it would be so easy!

  30. Lieke

    Thanks, it works great.
    Is there a way to add a checkbox?

  31. Fahad Rafiq

    WordPress websites and blogs are frequent targets of spam comments. To effectively stop the link spammers it is best to remove the “Website” field from the WordPress comment section. Learn 2 methods in this tutorial on how to remove the WordPress website field.
    Source: http://www.cloudways.com/blog/how-to-remove-url-field-from-wordpress-comment-form/

  32. Rub

    Thanks, this help me a lot.

    If I need only to save the data and show it only on the user profile and I do not need to retrieve it, I can only use add option, upload the file and add the data to the user?

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!

Recently on David Walsh Blog

  • OSCON Portland:  Conference  Discount!

    O'Reilly puts on the best web industry conferences in the world.  These conferences include Fluent Conference, Velocity Conference, and the upcoming OSCON in Portland, Oregon from July 20-24.  Open Source Convention (OSCON) is a conference that focuses specifically on open source developers and the tools and possibilities...

  • Follow Redirects with cURL

    I love playing around with cURL. There's something about loading websites via command line that makes me feel like some type of smug hacker, just like tweeting from command line does. I recently cURL'd the Google homepage and saw the following: I found it weird that Google...

  • Developers Have WordPress, Amateurs Have Squarespace, Professional Designers Have the NEW Webydo!

    Web design platforms have traditionally come in one of two varieties. There are the solutions like WordPress and Drupal that are incredibly powerful, but an understanding of web development and coding is required to be able to use those platforms effectively. On the other side of the...

  • Chris Coyierâs Favorite CodePen Demos II

    Hey everyone! Before we get started, I just want to say it’s damn hard to pick this few favorites on CodePen. Not because, as a co-founder of CodePen, I feel like a dad picking which kid he likes best (RUDE). But because there is just so...

  • GSAP + SVG For Power Users: Motion Along A Path

    Now that the GreenSock API is picking up steam, there are many tutorials and Getting Started guides out there to provide good introductions to the library, not to mention GreenSock’s own Forum and Documentation. This article isn’t intended for beginners, but rather a...