How to add Custom Fields to user profile in WordPress
This tutorial will show you the way to add custom fields for user profile in dashboard. This is very simple, ease of use & light code to follow.
So, now move to the point. Just open your functions.php
file & paste the below code:
// CUSTOM USER PROFILE FIELDS function user_custom_additionalfields( $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'; return $contactmethods; } add_filter('user_contactmethods','user_custom_additionalfields',10,1);
NOTE: You can change your desired input name & value.
Once you paste the above code you will able to see below fields in user profile:
There are two options to view this value in front. You can choose anyone from below:
OPTION-1:
<?php the_author_meta('contact_phone_mobile', $current_author->ID);?>
OPTION-2:
<?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>
Hope this shortest function helped you to add your own custom user fields in WordPress. Still if you face any trouble, feel free to contact me by dropping a message.
Thanks.
This post has already been read 4737 times!
I want to add several checkbox to a page and a button and when user clicks on that it should take user to another page and display the value of checkbox checked.
Hi Abhi,
Are you talking about meta box for page or profile ? And also we need to know your complete requirement and condition. Thanks.