I just opened my wheelie bin and a wasp flew out. What kind of sick person would throw a wasp in a bin? 1 day ago


Nov 09
24th

Add Twitter links to your WordPress posts


Want an easier way to add links to Twitter user pages? Here’s a quick solution.

Add the following code to your functions.php file within your theme folder…

add_filter('the_content', 'link_to_twitter');
function link_to_twitter($content) {
    $start=strpos($content,"[@");
    while ($start!=0) {
        $code=substr($content,$start+2,strpos($content,"]",$start)-$start-2);
        $content=str_replace("[@".$code."]",'<a href="http://twitter.com/'.$code.'" target="_blank">@'.$code.'</a>',$content);
        $start=strpos($content,"[@",$end);
    }
    return $content;
}

Now, you simply need to simply specify a Twitter username within square brackets and it will be replaced with the same username, but now with a link to Twitter.

For example, add [@dartiss] to your post and it will display as @dartiss.


Share this on del.icio.us Digg this! Email this Share this on Facebook Share this on LinkedIn Send this page to Print Friendly Share this on Reddit Share it on StumbleUpon Tweet This!

No Comments

There are no comments at present.

No Pingbacks/Trackbacks

There are no pingbacks/trackbacks at present.

No Tweetbacks

There are no tweetbacks at present.

Leave a Comment

All comments are authorised before appearing - you should receive an email once this has been done.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

64 queries in 0.964 seconds.