Customising Contact Fields in WordPress User Profiles


Customising contact fields in WordPress user profiles is easy using filters.

Just create a simple PHP function in your plugin (read more about why functionality like this should be kept out of your theme’s functions.php here), adding all the new contact methods you need. For example:

function yourprefix_contactmethods( $contactmethods ) {
$contactmethods['twitter'] = 'Twitter';
$contactmethods['facebook'] = 'Facebook';
return $contactmethods;
}
add_filter('user_contactmethods','yourprefix_contactmethods',10,1);

This function will give every user profile new Twitter and Facebook fields under the heading ‘Contact Info’.

Twitter and Facebook User Profile Contact Methods
Twitter and Facebook Fields in User Profile

 

The array key ['twitter'] defines the name and id of your new form field, and the second part 'Twitter' defines the label. You can add as many different contact methods as you like.

In your theme or plugin, you can access the new user data with the WordPress get_user_meta() function, using something like this:

<a href="<?php echo get_user_meta( $userID, 'facebook', true ); ?>"

For more info, see the Codex.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>