Created
February 6, 2017 21:34
-
-
Save danemorgan/cfe00a8118511a3bfd1ad23f9af9ac8e to your computer and use it in GitHub Desktop.
Removes nofollow from rel tags in comment links with trusted in their class attribute.
This file contains 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
<?php | |
add_filter( 'comment_text', 'dmm_follow_trusted_comment_links' ); | |
/** | |
* @param $comment_content | |
* | |
* Adds rel="nofollow target="_blank" to external and /go/ links in comment section. | |
* | |
* | |
* @return mixed|string | |
* @internal param $commentContent | |
* @internal param $comment | |
*/ | |
function dmm_follow_trusted_comment_links( $comment_content ) { | |
$comment_content = preg_replace( '%(<a[^>]*)(?:(?:(?:(\brel="[^"]*)(?:(?: *)(?:nofollow)(?: *))([^"]*"))([^>]*)(\bclass="[^"]*trust[^"]*"))|(?:(\bclass="[^"]*trust[^"]*")([^>]*)(?:(\brel="[^"]*)(?:(?: *)(?:nofollow)(?: *))([^"]*"))))([^>]*>)%', | |
'$1$2$3$4$5$6$7$8$9$10', | |
$comment_content); | |
return $comment_content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment