Last active
May 6, 2021 23:42
-
-
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
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 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