The default WordPress user profile page does not have a field for Twitter profile URL.

user_contactmethods filter allows for theme or plugin developers to modify the default set of fields in Contact Information section of wp-admin/profile.php and wp-admin/user-edit.php

The code snippets below illustrate how to add Twitter username as Contact Information field (functions.php) and how to get username for output in your loop or templates (single.php).

<?php
/**
* Add Twitter handle/username to User Contact Information
*
* @param $user_contact
*
* @return array
*/
function user_contact_add_twitter( $user_contact ) {
$user_contact['twitter'] = __( 'Twitter Username' );
return $user_contact;
}
add_filter( 'user_contactmethods', 'user_contact_add_twitter' );

view raw
add_user_twitter.php
hosted with ❤ by GitHub

<?php
/**
* Get Twitter username for current post author
*/
$twitter = get_the_author_meta( 'twitter', get_the_author_meta( 'ID' ) );

view raw
get_twitter_user.php
hosted with ❤ by GitHub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s