Websnippetz

Get cool snippets on php, css, jQuery, Magento and wordpress

Add custom fields in user profile

Place the code below into your functions.php file to add custom user profile fields. Edit or add lines as you see fit.
Remember not to remove the line: return $contactmethods; otherwise this won’t work.

<br />// CUSTOM USER PROFILE FIELDS<br /> function my_custom_userfields( $contactmethods ) {<br />     // ADD CONTACT CUSTOM FIELDS<br />     $contactmethods['contact_phone_office']     = 'Office Phone';<br />     $contactmethods['contact_phone_mobile']     = 'Mobile Phone';<br />     $contactmethods['contact_office_fax']       = 'Office Fax';<br />     // ADD ADDRESS CUSTOM FIELDS<br />     $contactmethods['address_line_1']       = 'Address Line 1';<br />     $contactmethods['address_line_2']       = 'Address Line 2 (optional)';<br />     $contactmethods['address_city']         = 'City';<br />     $contactmethods['address_state']        = 'State';<br />     $contactmethods['address_zipcode']      = 'Zipcode';<br />     return $contactmethods;<br /> }<br /> add_filter('user_contactmethods','my_custom_userfields',10,1);<br />

To display custom fields you can use one of the two methods listed below.
Accessing fields
Option 1:
the_author_meta('facebook', $current_author->ID);
Option 2:

<br />&lt;?php $current_author = get_userdata(get_query_var('author')); ?&gt;<br />&lt;a href=&quot;&lt;?php echo esc_url($current_author-&amp;gt;contact_phone_office);?&gt;&quot; title=&quot;office_phone&quot;&gt; Office Phone&lt;/a&gt;<br />

In this way you can add custom fields in user profile

karthi s

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: