Looking for a free WP Setup?Submit your request ASAP!HomeDomain PortfolioDisclosurePrivacy PolicyTOSContact

Link twitter handles in your posts automagically

twitter handle

This is a short but very useful guide for linking twitter handles inside your posts automatically.
Like this @MakisMour !!!!

If you ever typed a twitter handle and thought what if I could link that handle with its twitter profile without any further editing then this tutorial is for you.

This is in fact a quick tip I’ve read in wp.tutsplus.com and I found it very interesting for me and my blog visitors. Just follow steps below and be sure to keep backups for any files to be edited.

So here we go:

Step 1: Edit your theme functions.php file

Open or download your themes function.php(make sure you keep a backup first)

Step 2: Use the following code

Copy and paste the following code:

1
2
3
4
5
6
7
8
9
/** Link twitter handles with content */
function wptuts_twitter_handles($content) {
$pattern= '/(?< =^|(?<=[^a-zA-Z0-9-_.]))@([A-Za-z]+[A-Za-z0-9_]+)/i';
$replace= '@<a href="http://www.twitter.com/$1">$1';
$content= preg_replace($pattern, $replace, $content);
return $content;
}
 
add_filter( "the_content", "wptuts_twitter_handles" );

Step 3: Save and reload your page

After page reloads you should be able to see Twitter Handles auto-link to the related Twitter Profile like @MakisMour

Speak Your Mind