Add and/or remove WordPress user fields

Add and/or remove WordPress user fields

Simplicity should be a key goal in design and unnecessary complexity should be avoided. Therefore, Keep It Simple, Stupid. Or, minimalism!

Its certainly cause for celebration that — along with the overall, welcome minimalism visited upon the WordPress admin UI — as of the recent version of WordPress, rather antiquated User fields are no more. Navigate to Users > Your Profile and, unless explicitly added by a (possibly antiquated) theme or plugin, you see a welcome few user contact fields. Email, website, bio, etc. Strictly the basics.

Time comes though, when you want to add a reference to Skype or to Twitter or a link to Dribble or Facebook, etc. As usual, this is rather straightforward.

With the user_contactmethods filter, we can add or remove the available contact methods on a User’s profile page.

Defining the function

As usual, first we define a function. Lets call it butter_modified_fields(). This function will accept one argument $contact_methods which will be an associative array.

1 function butter_modified_fields( $contact_methods ){
2 // define the new/additional User fields here
3 }

After we’ve defined the function, we’ll then need to hook into the user_contactmethods filter. We’ll have this function make the contact_methods accept our new User fields form ids as the keys and the human-readable form labels as the values. Sounds more way complicated that it looks. Therefore, look:

1 function butter_modified_fields( $contact_methods ){
3 $contact_methods[‘skype’] = __(‘Skype Username’, ‘butter’);
4 $contact_methods[‘twitter’] = __(‘Twitter Username’, ‘butter’);
5 $contact_methods[‘dribbble’] = __(‘Dribbble Username’, ‘butter’);
6 $contact_methods[‘facebook’] = __(‘Full FB URL’, ‘butter’);
8 return $contact_methods;
9 }
11 add_filter(‘user_contactmethods’, ‘butter_modified_fields’);

Removing the old fields

Not too long ago, as mentioned, you had user fields for stuff like ‘aim’ and ‘jabber’. It’s not clear that there are any more teenagers from the late 90s left around still using aim. Nobody actually even knows what jabber is.

If you’re still looking at these fields in your User > Your profile views, chances are you need to promptly upgrade your installation to the latest WordPress version. If that’s an impossibility for you, fret not young Padawan, all you need to do is to adjust the above function. Having already added Skype, Twitter, Dribbble and Facebook fields, you can remove aim and jabber as follows:

1 function butter_modified_fields( $contact_methods ){
3 // lines where you added Skype, twitter, dribble, etc above
4 . . .
6 // Unset fields you don’t need
7 unset($contact_methods[‘aim’]);
8 unset($contact_methods[‘jabber’]);
10 return $contact_methods;
11 }
13 add_filter(‘user_contactmethods’, ‘butter_modified_fields’);

With that, your user profile UI is as svelte as you dreamt it to be. Be careful though, while reductive methods might work great in art class e.g. when working with charcoal on paper, in WordPress, removing core-defined functions and features isn’t a particularly good thing to do.

If the very sight of the fields makes you retch uncontrollably, by all means implement the removal of the contact method. Otherwise, its just as easy or arguably easier to altogether ignore the fields and not fill anything in them.

In fact, if you plan to distribute your theme through the top few marketplaces, avoid removing or crippling WordPress functionally in any way. As much as you morally (or otherwise) might disagree, your opinion won’t matter. Your crippled theme submission to these marketplaces will be categorically and summarily rejected. If you’re theming purely for fun and not profit, definitely experiment.

Showing the fields

Now that we’ve defined the function and understood that a more additive approach is far better than a reductive approach, we move on to using the function. On a multi-contributor magazine or newspaper site, for example, on each author’s profile page, you’d simply make a call for the relevant field like so:


Depending on what markup you use, you might want to wrap that in a conditional to first check that the field isn’t empty. Like so:


Add and/or remove WordPress user fields

Leave a Reply

Your email address will not be published. Required fields are marked *