search ]

Add Custom User Profile Fields in WordPress

Add the following code to your functions.php file to add your own fields to the user profile page in the WordPress admin.


// CUSTOM USER PROFILE FIELDS
function my_custom_userfields( $contactMethods ) {

    // ADD CONTACT CUSTOM FIELDS
    $contactMethods['contact_phone_office']     = 'Office Phone';
    $contactMethods['contact_phone_mobile']     = 'Mobile Phone';
    $contactMethods['contact_office_fax']       = 'Office Fax';

    // ADD ADDRESS CUSTOM FIELDS
    $contactMethods['address_line_1']       = 'Address Line 1';
    $contactMethods['address_line_2']       = 'Address Line 2 (optional)';
    $contactMethods['address_city']         = 'City';
    $contactMethods['address_state']        = 'State';
    $contactMethods['address_zipcode']      = 'Zipcode';
}
add_filter('user_contactmethods','my_custom_userfields',10,1);

To display these fields you can use one of the following methods:

the_author_meta('facebook', $current_author->ID)
<?php $current_author = get_userdata(get_query_var('author')); ?>
<p><a href="<?php echo esc_url($current_author->contact_phone_office);?>" title="office_phone"> Office Phone</a></p>

For a more robust approach to custom fields, see Beginner’s Guide to Advanced Custom Fields.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo