Last active
December 18, 2015 02:39
-
-
Save psflannery/5712628 to your computer and use it in GitHub Desktop.
Once you saved the file all twitter usernames in posts and comments will automatically be linked to their Twitter profiles. Usernames have to be written under the form @username.
@link: http://www.wpbeginner.com/wp-tutorials/how-to-automatically-link-twitter-usernames-in-wordpress/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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