Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #50154
    alexmo
    Member

    Hello, I want to place label “nofollow” to all external links on my website.

    I used a plugin does not work.

    I have also introduced the following code in functions.php file,

    add_filter('the_content', 'auto_nofollow');
    
    function auto_nofollow($content) {
        //return stripslashes(wp_rel_nofollow($content));
    
        return preg_replace_callback('/<a>]+/', 'auto_nofollow_callback', $content);
    }
    
    function auto_nofollow_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;
    }

    but does nothing.

    as I can do

    Thanks

    #50182
    Sakin
    Keymaster

    @alexmo: This is quite complicated and link can be there in many places where you add in links. So, I suggest you to try plugin instead. There are lot of no follow plugin in WordPress.org and other premium plugins provider.

    #50240
    alexmo
    Member

    Ok, Thanks

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘add to Nofollow’ is closed to new replies.