Last updated on February 3, 2024

Add Custom User fields

Don’t know where to add this snippet? Read our guide: How to add code snippets.

Add custom fields to a user in WordPress.

To add custom fields to the user profile in WordPress, you can use the user_contactmethods filter in your theme’s functions.php file. The following code snippet will add a new field for the user’s Twitter handle:

function wpsnippets_add_twitter_field( $user_contactmethods ) {

    $user_contactmethods[ 'twitter' ] = __( 'Twitter Handle', 'wpsnippets' );

    return $user_contactmethods;
}

add_filter('user_contactmethods', 'wpsnippets_add_twitter_field' );

This code adds a new field to the user profile by adding a new key-value pair to the $user_contactmethods array. The key twitter is the name of the new field, and the value Twitter Handle is the label that will be displayed next to the field. You can modify these values to match the field you want to add.

Last updated on February 3, 2024. Originally posted on May 3, 2023.

Leave a Reply

Your email address will not be published. Required fields are marked *