Guest User

Untitled

a guest
Feb 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function rel_nofollow( $content ) {
  2. return preg_replace_callback( ‘/]+/’, ‘rel_nofollow_callback’, $content );
  3. }
  4. add_filter( ‘the_content’, ‘rel_nofollow’, 99999 );
  5.  
  6. function rel_nofollow_callback( $matches ) {
  7. $link = $matches[0];
  8. $exclude = ‘(‘. home_url() .’|http://([^.]+.)?(wp.org|wp.com))’;
  9. if ( preg_match( ‘#href=S(‘. $exclude .’)#i’, $link ) )
  10. return $link;
  11.  
  12. if ( strpos( $link, 'rel=' ) === false ) {
  13. $link = preg_replace( '/(?<=<as)/', 'rel="nofollow" ', $link );
  14. } elseif ( preg_match( '#rel=S(?!nofollow)#i', $link ) ) {
  15. $link = preg_replace( '#(?<=rel=.)#', 'nofollow ', $link );
  16. }
  17. return $link;
  18. }
Add Comment
Please, Sign In to add comment