Two years ago, Twitter launched the Twitter Anywhere API, which made it very easy for us to mention Twitter usernames and automatically link them to the correct profile. It also allowed beautiful hovercards with additional information. Sadly, Twitter decided to retire the Anywhere API on December 6, 2012. Since we regularly mention users' Twitter handles in our post content, it only made sense to find a way to automatically link Twitter usernames in WordPress. Instead of relying on a third party script, we decided to write a short and simple plugin to take care of the job. In this article, we'll show you how to automatically link Twitter usernames in WordPress when you mention it after the @ sign like so:@wpbeginner.
All you have to do is open a blank .php file and call it wpb-twitlinks.php. Then copy the code below and save it there. Upload the file to your plugins folder and simply activate the plugin.
Note that since we only use this on our single posts and pages, we only have the filter for content. You can always extend this function to statements as well by adding the following line:
add_filter ('the_excerpt', 'twtreplace');
We are not saying that this is the only method that exists. There are probably a lot of jQuery solutions available. This is the fastest and most effective solution in our opinion.