Automatically Link to Twitter Usernames in Content : This is especially useful if you are running a website that focuses a lot on Twitter (probably a viral content site, etc.)

The following code snippet for functions.php converts all @ mentions in your content to their respective Twitter profiles.

Why dont I just use a plugin? Good question. The more plugins you have installed on your WordPress installation the slower your site loads. Remember search engines use your page load speed as a ranking factor. So if you want your SEO to be effective and your rankings increased on search engines, one must pay attention to SEO factors such as this. If your not comfortable with code or SEO we can help. Tap here.

For example, an @happy mention in your content will be converted to a link to the Twitter account “” (“happy” being the username):

function content_twitter_mention($content) {
return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1<a href=\"$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>", $content);
add_filter('the_content', 'content_twitter_mention');   
add_filter('comment_text', 'content_twitter_mention');

Related Posts:

Choose your preferred blog CMS platform

WordPress Posts vs Pages

Introduction to JavaScript – Create a Variable: let

CSS, HTML, JAVASCRIPT, Online Compiler. Code on the go by

Introduction to JavaScript – Control Flow: if/else Statements

Show Post Thumbnails in RSS Feed – WordPress

Create a PayPal Donation Shortcode – WordPress

What is a Shortcode in WordPress?

What is a robot.txt file?

Formatting Text in WordPress Posts (Tiny MCE Advanced for WordPress)

Redirect New Registered Users to a Specific Page – WordPress