dane-m
2/6/2017 - 9:34 PM

Removes nofollow from rel tags in comment links with trusted in their class attribute.

Removes nofollow from rel tags in comment links with trusted in their class attribute.

<?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;
}