preg_replace_callback nofollow, dofollow

Discussion in 'PHP' started by bumbar, Jan 3, 2013.

  1. #1
    Hello!

    Here is the cod snip from web, wordpress.

    
    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;
    }
    PHP:
    I want to ask is it possible to put all internal links 'rel=dofollow'

    Also does it make sense 'rel=dofollow' ?

    Thank you!
     
    Last edited: Jan 3, 2013
    bumbar, Jan 3, 2013 IP
  2. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    #2
    The code ( should ) match only urls which does not contain your blog url in href code, so only external links.
    If internal links are nofollow as well the following part might be wrong, not to sure, think its deprecated or your wp is setting for home url and blog url are different. Either of those should explain the behavour

    Can you test to replace
    
    $site_link = get_bloginfo('url');
    
    Code (markup):
    with this
    
    $site_link = get_bloginfo('wpurl');
    
    Code (markup):
     
    Basti, Jan 8, 2013 IP
  3. ryan_uk

    ryan_uk Illustrious Member

    Messages:
    3,983
    Likes Received:
    1,022
    Best Answers:
    33
    Trophy Points:
    465
    #3
    There is no point in making links dofollow. Dofollow is just a term to describe links that don't have the nofollow attribute.
     
    ryan_uk, Jan 8, 2013 IP