Wednesday, 14 May 2014

Automatically link Twitter usernames in WordPress

[Wordpress hack]
Are you using Twitter a lot? Today’s recipe is a cool piece of code to automatically link Twitter usernames on your posts, pages, and comments.

Paste the code below into your functions.php file:
function twtreplace($content) {
 $twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1@$2",$content);
 return $twtreplace;
}

add_filter('the_content', 'twtreplace');   
add_filter('comment_text', 'twtreplace');

No comments:

Post a Comment