Skip to content

Instantly share code, notes, and snippets.

@hamidrezayazdani
Last active October 15, 2021 18:47
Show Gist options
  • Save hamidrezayazdani/8954d49e0a485ed70d993a7d247808c5 to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/8954d49e0a485ed70d993a7d247808c5 to your computer and use it in GitHub Desktop.
نوفالو کردن لینک های خارجی پیکوفایل
<?php
/**
* Add "nofollow" to picofile external links
*/
function ywp_nofollow_picofile_extrenal_links( $content ) {
$domain = "https://www.picofile.com";
preg_match_all( '~<a.*>~isU', $content, $matches );
for ( $i = 0; $i <= count( $matches[0] ); $i ++ ) {
if ( isset( $matches[0][ $i ] ) && ! preg_match( '~nofollow~is', $matches[0][ $i ] )
&& ( preg_match( '~' . preg_quote( $domain ) . '~', $matches[0][ $i ] )
|| ! preg_match( '~' . get_bloginfo( 'url' ) . '~', $matches[0][ $i ] ) )
) {
$result = trim( $matches[0][ $i ], ">" );
$result .= ' rel="nofollow">';
$content = str_replace( $matches[0][ $i ], $result, $content );
}
}
return $content;
}
add_filter( 'the_content', 'ywp_nofollow_picofile_extrenal_links' );
// The code goes to your active theme(or child theme) functions.php file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment