Web Design & Development

Adding A Custom User Profile Field To Your Website

Use the following code to add a custom user profile field to your website.

You can add it to your functions.php (via Code Snippets Plugin).

// add custom field to user profile
function fs_add_custom_user_profile_fields( $user ) {
	<h3><?php _e('Extra Profile Information', 'fs_custom'); ?></h3>
	<table class="form-table">
				<label for="odoo_customer_id"><?php _e('Odoo Customer ID', 'fs_custom'); ?></label>
				<input type="text" name="odoo_customer_id" id="odoo_customer_id" value="<?php echo esc_attr( get_the_author_meta( 'odoo_customer_id', $user->ID ) ); ?>" class="regular-text" /><br />
				<span class="description"><?php _e('Please enter Odoo Customer ID.', 'fs_custom'); ?></span>
<?php }

function fs_save_custom_user_profile_fields( $user_id ) {
	if ( !current_user_can( 'edit_user', $user_id ) )
		return FALSE;
	update_usermeta( $user_id, 'odoo_customer_id', $_POST['odoo_customer_id'] );

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

add_action( 'personal_options_update', 'fs_save_custom_user_profile_fields' );
add_action( 'edit_user_profile_update', 'fs_save_custom_user_profile_fields' );

Optionally, you can add this field to the back-end list of users too, in order to easily see the value of the field:

// Now let's add this field to the User list in the backend
function new_modify_user_table( $column ) {
    $column['odoo_customer_id'] = 'Odoo Customer ID';
    return $column;
add_filter( 'manage_users_columns', 'new_modify_user_table' );

function new_modify_user_table_row( $val, $column_name, $user_id ) {
    switch ($column_name) {
        case 'odoo_customer_id' :
            return get_the_author_meta( 'odoo_customer_id', $user_id );
    return $val;
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );

This was meant to add a custom field titled “Odoo Customer ID” to the user profile back-end for admin purposes.

You would want to adjust any references to the “Odoo Customer ID” and update the field to be something other than “odoo_customer_id”.

See our featured website design work

Check out some of the beautiful websites we’ve built for over 2,000 clients.

We offer WordPress support & maintenance

Shake the stress of ongoing maintenance with plans supported by our team of WordPress experts.

Related articles