Forum Moderators: coopster
<?php
if (!class_exists('ExternalNofollow')) {
class ExternalNofollow
{
static function init()
{
add_filter('the_content', array(__CLASS__, 'nofollow'));
}
function nofollow($content)
{
//return stripslashes(wp_rel_nofollow($content));
return preg_replace_callback('/<a[^>]+/', array(__CLASS__, 'callback'), $content);
}
function singlePostDoFollow($content){
global $post;
if(get_post_meta($post->ID,"dofollow",true) === 1){
//return str_replace('rel="nofollow"','',$content);
return preg_replace('~<a ([^>]*)\s*(["|\']{1}\w*)\s*nofollow([^>]*)>~U','<a ${1}${2}${3}>', $content);
}else{
return $content;
}
}
function callback($matches)
{
$link = $matches[0];
$site_link = get_bloginfo('url');
if (strpos($link, 'rel') === false) {
$link = preg_replace("%(href=\S(?!$site_link))%i", 'rel="nofollow" $1', $link);
} elseif (preg_match("%href=\S(?!$site_link)%i", $link)) {
$link = preg_replace('/rel=\S(?!nofollow)\S*/i', 'rel="nofollow"', $link);
}
return $link;
}
}
ExternalNofollow::init();
}
?> function singlePostDoFollow($content){
global $post;
if(get_post_meta($post->ID,"dofollow",true) == 1){
//return str_replace('rel="nofollow"','',$content);
return preg_replace('~<a ([^>]*)\s*(["|\']{1}\w*)\s*nofollow([^>]*)>~U','<a ${1}${2}${3}>', $content);
}else{
return $content;
}
}
add_filter('the_content', 'singlePostDoFollow');