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) {
    while ($start!=0) {
        $content=str_replace("[@".$code."]",'<a href="'.$code.'" target="_blank">@'.$code.'</a>',$content);
    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.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.