Changing Contact Fields

The built-in contact fields are not always terribly useful. Business users need to add job titles, some social networks value Twitter usernames over instant messenger accounts, and so on.

WordPress has a filter function that allows you to change the fields that appear in the Contact Info section. The code is fairly simple, as shown in Listing 10-3. Place it in your theme's functions.php file or in a new plugin (as you saw in in Chapter 9).

Listing 10-3. Changing user profile contact fields

// change user contact fields function change_contactmethod( $contactmethods ) { // Add some fields

$contactmethods['twitter'] = 'Twitter Name (no @)';

$contactmethods['phone'] = 'Phone Number';

// Remove AIM, Yahoo IM, Google Talk/Jabber unset($contactmethods['aim']);



return $contactmethods;


This function accepts an associative array of contact fields. You've added three new fields, where the array key is a short name for the field and the value is the label that will appear in the form. Then you've removed the array items containing the fields you no longer want—all three instant messenger accounts, in this case. Of the default contact fields, these are the only three you can remove; the e-mail and URL fields must remain.

Finally, you need to call the filter. The add_filter() function takes four arguments: the name of the built-in filter ('user_contactmethods'), the name of the custom function ('change_contactmethod'), a priority (10, in this case, means the filter has a low priority and will be called after most other filters), and finally the number of arguments the custom function requires (in this case, just one).

Once you place the above code into your functions.php file, you'll see the new contact fields displayed when you view a user's profile, as shown in Figure 10-3.

Figure 10-3. The new contact fields in the user profile
Top Twitter Techniques

Top Twitter Techniques

Do you find it difficult to use Twitter for profits? Discover The Secrets To Using Twitter And Have Great Success In Your Business! How To Tweet Your Way To Network Marketing Success. How would you like to get a boost to your business today by using Twitter the right way?

Get My Free Ebook

Post a comment