Last active
December 25, 2015 12:39
-
-
Save scrubmx/6978304 to your computer and use it in GitHub Desktop.
WordPress Helper Function:Convert url's @mentions and hashtags to links
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 parseTwitterContent($string) { | |
| $links = make_clickable($string); | |
| $patterns = array("/@([a-zA-Z0-9_]+)/", "/#([a-zA-Z0-9_]+)/"); | |
| $replace = array( | |
| "<a href='http://twitter.com/$1' target='_blank'>@$1</a>", | |
| "<a href='http://twitter.com/#$1' target='_blank'>#$1</a>" | |
| ); | |
| return preg_replace($patterns, $replace, $links); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment