Blog: WordPress
Closeup of old typewriter

Add New Fields To WordPress User Profiles

Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

On your WordPress user profile, in the back end of the site, you’ll notice most themes have places to input your website, Facebook, Twitter, and Google+ URLs.

Many years ago, you had to add these manually, and WordPress (back in the day) used to have places to set your AIM (remember that?), Jabber, and Yim profiles.

But let’s say you want to set new places on a user profile for them to input information. How would you go about doing that?

Reasons For Adding New Contact Methods

There are numerous reasons you might want to add new contact methods to your user profiles.

Contact Info on WordPress Admin Screen

For one, your theme may user that information and output those URLs to a public facing profile for each user. You may also want to display user-specific information in an author bio for each person who writes for your site.

The Code Snippet

This would be something you add to your functions.php file in your theme.

What if you wanted to add new fields to your user profiles for their LinkedIn, YouTube, and Instagram URLs? That would look like this:


/**
 * Add new user profile fields
 *
 */

if ( ! function_exists( 'ld_modify_contact_methods' ) ) :

    function ld_modify_contact_methods( $contactmethods ) {
        $contactmethods['linkedin'] = __( 'Linked In' );
        $contactmethods['youtube'] = __( 'YouTube' );
        $contactmethods['instagram'] = __( 'Instagram' );

        return $contactmethods;
    }
    add_filter('user_contactmethods','ld_modify_contact_methods', 10, 1);

endif;

Let’s say against better judgement, you want to remove the Facebook, Twitter, and Google+ fields from user profiles. Now our custom function would look like this:


/**
 * Add / delete new user profile fields
 *
 */

if ( ! function_exists( 'ld_modify_contact_methods' ) ) :

    function ld_modify_contact_methods( $contactmethods ) {
        $contactmethods['linkedin'] = __( 'Linked In' );
        $contactmethods['youtube'] = __( 'YouTube' );
        $contactmethods['instagram'] = __( 'Instagram' );
        unset($contactmethods['facebook']);
        unset($contactmethods['twitter']);
        unset($contactmethods['googleplus']);

        return $contactmethods;
    }
    add_filter('user_contactmethods','ld_modify_contact_methods', 10, 1);

endif;

What’s Happening In This Code?

There’s already a built-in filter in WordPress core called user_contactmethods. What we’re doing is hooking into that, and adding and deleting our user profile fields, and saving that information via field keys.

The variable we are passing new values to is $contactmethods. What you call this variable doesn’t matter so much, as long as it is consistently used.

We add the fields we want to append to our user profiles first. If we have any fields we want to delete (or unset), we do that next.

Finally, we return our changes to our variable, and pass our whole custom function through the filter user_contactmethods.

We can later access these values for each user.

For example, if we we wanted to output the link to a LinkedIn page for a site author in their bio, we could now use something like this in a page template.


<?php if ( get_the_author_meta('linkedin') ) :  ?>
	<?php the_author_meta('linkedin'); ?>
<?php endif; ?>


Avatar for John Locke

John Locke is a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown Design & SEO.

17 comments on “Add New Fields To WordPress User Profiles

  1. Hi Kelechi:

    I just double checked this to make sure nothing changed in 4.5. Here’s what may be going on.

    Default WordPress names those fields as shown in the code examples above. Those are stored with those particular variable names.

    your particular theme may be naming those fields something different as the variables. Or it may be adding them later in the functions.php file, depending on where you copy-pasted this code. Those are the first places I would start looking.

    To get the variable names for the fields you want to unset, you can go to your profile page in the backend, and Right-click > Inspect Element over that field. Find the corresponding label element for that field. Whatever is in label for=" " should be your variable name for that field. Try unsetting those.

    Also make sure this code snippet is at the bottom of your functions.php file.

  2. Interesting post, however I’ve tried the snippet but am having the same issue as Kelechi — trying to unset the social profiles for Twitter, Facebook and LinkedIn and it simply won’t work. I’ve inspected the element to check the label names and they are simply ’twitter’, ’facebook’, ’linkedin’ — not sure what else to try now, any ideas? I’m using the latest version of WordPress.

    1. Hi Gillian:

      I just tested this again with some other sites to make sure the code snippet is working correctly. What it sounds like is your theme might be adding those user fields under different values.

      The reason I say this is LinkedIn isn’t one of the default user fields in WordPress core. With a fresh install of WordPress, and a default theme, under Users > Your Profile > Contact Info you would see inputs for Email (required), Website, Google+, Twitter username (without @), and Facebook profile URL.

      If you have more input fields than this with your particular theme, those are being added somewhere in the theme.

      What you may have to do is investigate your theme files and try to locate what values those input fields are being registered as, and then you should be able to unset them. I would look first in the functions.php, and then go to any core functions files that may be in the theme. Sometimes these are in an includes folder.


      It also occurs to me that you may be trying to do something besides eliminate the input fields on a user’s profile. For example, you may just want to get rid of some social icons that appear on the front-end (public view) of the site.

      If that is the case, you can use a child theme to change specific template files without altering the base theme files.

  3. Hi John, second time on this message to get the notify box checked. Thanks, again, for any suggestions you have for me (and your subscribers, too). DVH

    Hi John, thanks for the very clear explanation. Like the others who have commented, I am unable to get this code to work as described. I’m on WP 4.6.1, and am using the Themeco X theme. So far, I’ve managed to hide / delete the color picker and other profile fields down to the Personal options set by modifying the X-Child theme’s functions.php file. I’ve also been able to hide / delete the bio info in the About Yourself section. So these last three user contact methods just don’t want to go away. I’ve checked the functions.php files (all of them) on this server instance, and don’t find anything that would obviously cause a problem. Any suggestions would be most welcome. Regards, Don Hirst

  4. John, I’m trying to remove the three listed in your post; Facebook, Twitter, Google+. I copied the code snippet from your post to my functions.php file and restarted apache2 webserver. When I refreshed the display, those pesky items were still showing on the profile page.
    Don

    1. Hi Don:

      When you go to Users > Your Profile and you right-click > Inspect Element on those three labels, what is it saying the label is for in each of those three cases?

      Refer to this screenshot below:

      Users > Your Profile + Right-click > Inspect element

  5. Hi Don:

    Interesting. So you are able to hide other fields on a user profile, but not Facebook, Google+, and Twitter?
    You are putting the second of the three code snippets in the article at the end of your functions.php file?

  6. Hi Don:

    So what puzzles me is when I test this code on any other WordPress site, it removes the contact info fields from the User Profiles. Maybe the X theme is adding them again after the regular functions.php file. It’s hard to say without looking inside the actual theme.

    Here’s a question. Why are you trying to remove these particular contact info fields? Do they show up somewhere else in the front-end display of the theme? What do they correlate to on the site?

  7. I checked the X theme’s functions.php files and didn’t find anything. I’m using a number of other WP plugins, but don’t think they interact with the user profile. The site is for folks who generally are not familiar with WordPress and computers in general, so I’m trying to simplify the user profile page, but without going to another plugin to build a whole new profile area. For now, I think, we’ll just let it go. I have Theme-My-Login plugin working, so could use that to build a profile page, if I had to.

    Don

  8. Thanks. The X-Theme does control display of social networking links, so perhaps that is interacting with the profile page. I’m not going to spend any more time on it, though.
    DvH

  9. I find it hilarious that there are SEVERAL plugins that completely overcomplicate the process of adding extra fields. Your code snippet saved me once again. Thank you, sir.

Join the Conversation

Your email address will be kept private. Required fields marked *.