/**
 * Register new user contact details.
 *
 * @param array $fields User contact fields.
 *
 * @return array
 */
function dorzki_register_new_contact_details( $fields ) {

	$fields['github'] = __( 'GitHub', 'dorzki' );

	return $fields;

}

add_filter( 'user_contactmethods', 'dorzki_register_new_contact_details' );

How to use it?

Usually adding functionality to a WordPress site is by creating a plugin.
However you can simply copy the code and paste it in your child theme’s functions.php file at the end of the file, just before ?>.

For JavaScript code you will need to add them to your theme’s main JavaScript file.

Having issues with the code?

If the code doesn’t work or you get an error please let us know in the comments section.
We will do our best to fix it as-soon-as-possible and update the code on this page.

Comments

  1. Alon

    How can I display those fields?

    Reply
    1. Dor Zuberi

      Hi Alon,
      In order to display one of the contact fields, use the following code:

      echo get_user_meta( $user->ID, 'github', true );

      Replace the `$user` with the current user object or with the current author page ID.

Leave a Reply