Last active
January 3, 2016 12:29
-
-
Save johnbocook/8463035 to your computer and use it in GitHub Desktop.
Used in Wordpress functions.php. It searchs the content of the post for a single word after an @ symbol and autolinks it to their twitter profile.
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
| function content_twitter_mention($content) { | |
| return preg_replace('/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1<a href=\"http://twitter.com/$2\" target=\"_blank\" rel=\"nofollow\">@$2</a>", $content); | |
| } | |
| add_filter('the_content', 'content_twitter_mention'); | |
| add_filter('comment_text', 'content_twitter_mention'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment