Skip to content

Instantly share code, notes, and snippets.

@nutsandbolts
Last active December 27, 2015 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nutsandbolts/7352697 to your computer and use it in GitHub Desktop.
Save nutsandbolts/7352697 to your computer and use it in GitHub Desktop.
Automatically link Twitter names to Twitter URL in blog posts and comments (functions.php)
<?php
//* DO NOT include the opening PHP tag
//* Automatically link Twitter names to Twitter URL
function twtreplace($content) {
$twtreplace = preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/',"$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>",$content);
return $twtreplace;
}
add_filter('the_content', 'twtreplace');
add_filter('comment_text', 'twtreplace');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment