Guest User

Untitled

a guest
Jan 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function add_nofollow( $content ) {
  2.  
  3. $my_xurl = "*.openstreetmap.fr";
  4. $my_purl = "*.tile.openstreetmap.fr";
  5. preg_match_all( '~<a.*>~isU', $content, $uri_match );
  6.  
  7. for ( $i = 0; $i <= sizeof( $uri_match[0] ); $i ++ ) {
  8. if ( isset( $uri_match[0][ $i ] ) && ! preg_match( '~nofollow~is', $uri_match[0][ $i ] )
  9. && ( preg_match( '~' . preg_quote( $my_xurl ) . '~', $uri_match[0][ $i ] ))
  10. && ( preg_match( '~' . preg_quote( $my_purl ) . '~', $uri_match[0][ $i ] ))
  11. ) {
  12. $uri_change = trim( $uri_match[0][ $i ], ">" );
  13. $uri_change .= ' rel="nofollow">';
  14. $content = str_replace( $uri_match[0][ $i ], $uri_change, $content );
  15. }
  16. }
  17.  
  18. return $content;
  19. }
  20.  
  21. add_filter( 'the_content', 'add_nofollow' );
Add Comment
Please, Sign In to add comment