Add and remove fields in the profile

The post is also available in: Swedish

The user profile there is various contact fields that can be edited. It can however happen that we wish for other attributes than those already specified.

I will in this post go through how to edit this form, both by adding new fields and delete predefined.

The filter for this is called user_contactmethods and can be used as follows:

function callback( $contactmethods )
{
    // Adding fields, Facebook, and Google + Twitter
    $contactmethods[ 'facebook' ] = 'Facebook';
    $contactmethods[ 'google' ]   = 'Google+';
    $contactmethods[ 'twitter' ]  = 'Twitter';

    // Removing fields AIM och Yahoo IM
    unset( $contactmethods[ 'aim' ] );
    unset( $contactmethods[ 'yim' ] );

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

Above, I have now added fields “Facebook”, “Google +” and “Twitter” to the profiles inwordpress. I also extinguished the fields “AIM” and “Yahoo IM”.
There is no link between how many fields you add and how many you have to remove.

In order to retrieve the stored data within the code, we use the method the_author_meta or get_the_author_meta, example follows:

the_author_meta( 'facebook' )

Links

http://wp.tutsplus.com/tutorials/quick-tip-add-extra-contact-methods-to-user-profiles/
http://yoast.com/user-contact-fields-wp29/