WordPress profile extra fields

There is a way in WordPress to add extra fields to WordPress users. While there’s a “default” set of contact fields AIM, Yahoo IM and Jabber / Google Talk, oftentimes even more fields are required. This is particularly true if you need to create WordPress customization where each user should have its own home page and functionality.

Here is how I added textarea field for the job position. I got the idea from Justin Tadlock website.

The PHP code you need for a custom textarea would look like this:

add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );

function my_show_extra_profile_fields( $user ) { ?>


Extra profile information

Describe what you do.
<?php } add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'jobpos', $_POST['jobpos'] ); }

And that’s it.You’ll just need to add this code to your functions.php file and it will rock. Just to mention that if you need straight textfields there is probable the better solution you can find on Yoast’s website. As I tested Yoast’s code works in WordPress 3.0 perfectly.


tags: & category: -