Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Last active December 25, 2015 12:39
Show Gist options
  • Select an option

  • Save scrubmx/6978304 to your computer and use it in GitHub Desktop.

Select an option

Save scrubmx/6978304 to your computer and use it in GitHub Desktop.
WordPress Helper Function:Convert url's @mentions and hashtags to links
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