In this code snippet we will share how to automatically link twitter usernames in WordPress. If you want to link twitter usernames, You need to add some line of code to theme’s functions.php file.

Add the following code to functions.php file:

/* Automatically link Twitter usernames */
function wpc_twitter_replace($content) {
	$twitter_replace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",$content);
	return $twitter_replace;
}
add_filter('the_content', 'wpc_twitter_replace');
How to Automatically Link Twitter Usernames in WordPress
5 (100%) 4 votes

(Visited 23 times, 1 visits today)

Leave a Comment

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