Skip to content

Instantly share code, notes, and snippets.

@WordPress-Handbuch
Last active May 6, 2021 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WordPress-Handbuch/e3a4290a79b2c41e4a946dd8f6191a92 to your computer and use it in GitHub Desktop.
Save WordPress-Handbuch/e3a4290a79b2c41e4a946dd8f6191a92 to your computer and use it in GitHub Desktop.
Parsing all WordPress post and page text, link all @ and # words to Instgram tags and profiles
function wh_add_social_links( $content ) {
$content = preg_replace( '/([^a-zA-Z0-9-_&])@([0-9a-zA-Z_]+)/', "$1<a href=\"https://www.instagram.com/$2/\" target=\"_blank\">@$2</a>", $content );
$content = preg_replace( '/([^a-zA-Z0-9-_&])#([0-9a-zA-Z_]+)/', "$1<a href=\"https://www.instagram.com/explore/tags/$2/\" target=\"_blank\">#$2</a>", $content );
return $content;
}
add_filter( 'the_content', 'wh_add_social_links' );
add_filter( 'comment_text', 'wh_add_social_links' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment