Considering how regularly new versions of Firefox now come along, that's quite some bug fix list in version 10! http://t.co/K3I2vLpW 1 week ago

24th
Nov 09

Add Twitter links to your WordPress posts



closeThis post was written 2 years 2 months 17 days days old, so is a bit old now. Feel free to read and comment on this post, just remember some things change with time and any facts in this post may not be accurate anymore.

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.

Delicious Digg Facebook LinkedIn Read It Later reddit StumbleUpon Twitter SeparatorEmail Google Translate PDF Online Print Friendly

No Comments

    No Pingbacks/Trackbacks

      Leave a Comment

      All comments are approved manually. No spam please, or comments that add nothing to the conversation.

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

      *

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