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

Was this article helpful?

0 0
The Twitter Blueprint

The Twitter Blueprint

Shortcut Straight To The Twitter Techniques That Are ESSENTIAL To You As An Internet Marketer, And Leave Out All The Padding And Fluff! What do you think limits your online profit more than anything? Sure there could be a dozen reasons but as a professional internet marketer I can tell you what one of the main leeches on my time is. Actually it's two things, LACK OF KNOWLEDGE and LEARNING CURVE.

Get My Free Ebook

Post a comment