ControlledChaos
5/7/2015 - 8:48 AM

Automatically link Twitter Usernames

Automatically link Twitter Usernames

<?php

function ccd_twt_replace( $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', 'ccd_twt_replace' );   
add_filter( 'comment_text', 'ccd_twt_replace' );

?>

Automatically link Twitter Usernames

WordPress Snippet