Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function rel_nofollow( $content ) {
- return preg_replace_callback( ‘/]+/’, ‘rel_nofollow_callback’, $content );
- }
- add_filter( ‘the_content’, ‘rel_nofollow’, 99999 );
- function rel_nofollow_callback( $matches ) {
- $link = $matches[0];
- $exclude = ‘(‘. home_url() .’|http://([^.]+.)?(wp.org|wp.com))’;
- if ( preg_match( ‘#href=S(‘. $exclude .’)#i’, $link ) )
- return $link;
- if ( strpos( $link, 'rel=' ) === false ) {
- $link = preg_replace( '/(?<=<as)/', 'rel="nofollow" ', $link );
- } elseif ( preg_match( '#rel=S(?!nofollow)#i', $link ) ) {
- $link = preg_replace( '#(?<=rel=.)#', 'nofollow ', $link );
- }
- return $link;
- }
Add Comment
Please, Sign In to add comment