Add username to twitter share

The following code snippet will add your twitter username to the end of a tweet shared from your website. Add this code to your theme’s functions.php file or a core functionality plugin.

Make sure to change “billerickson” to your twitter username.

/**
 * Shared Counts - Add username to twitter share
 *
 * @link https://www.billerickson.net/code/shared-counts-twitter-username
 * @author Bill Erickson
 *
 * @param array $link
 * @return array
 */
function be_shared_counts_twitter_username( $link ) {
	if( 'twitter' == $link['type'] ) {
		$link['link'] .= '&via=billerickson';
	}
	return $link;
}
add_filter( 'shared_counts_link', 'be_shared_counts_twitter_username' );

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk