Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Automatically link Twitter usernames in WordPress
SUBMITTED BY:
Guest
DATE:
Dec. 26, 2013, 6:25 a.m.
FORMAT:
PHP
SIZE:
571 Bytes
Raw
Download
Tweet
HITS:
856
Go to comments
Report
If you’re often quoting Twitter users on your blog, what about automatically link twitter usernames? Here is a nice regular expression to do so. Simply add this code to your functions.php file for it to work.
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');
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus