Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
in Q2A Core by
It would be nice to remove the nofollow on some "trusted domains" - I'm mainly thinking about other pages on my own site, but maybe I'll open it up as I see good sites we ought to "pass on link juice" (god I hate that phrase).

Anyway...whereabouts in the code would I need to look to change this?

1 Answer

+1 vote
Best answer
The function qa_html_convert_urls(...) in qa-app-format.php is the place to look. Unfortunately links are currently added via a big regular expression, so it won't be so easy to filter based on trusted domains. I guess the best way to do it would be to apply a second regular expression substitution, which looks for links to those trusted domains, and removes the nofollow.
edited by
UPDATE: see here for a better answer - http://question2answer.org/qa/8364/how-to-remove-nofollow-for-links-to-own-website


OK thanks! I added another regex after the original one. Here is the code from the function, in case it's useful for anyone else:

    $search = '/([^A-Za-z0-9])((http|https|ftp):\/\/\S+\.[^\s<>]+)/i';
    $replace = '\1<a href="\2" rel="nofollow">\2</a>';
    $html = trim( preg_replace($search, $replace, ' '.$html.' ') );
    // remove nofollow for my links
    $search = '/href="http:\/\/YOURDOMAIN\/([^"]*)" rel="nofollow"/i';
    $replace = 'href="http://YOURDOMAIN/\1"';       
    $html = trim( preg_replace($search, $replace, $html) );
    return $html;

Obviously, replace YOURDOMAIN with your actual domain name.
This is really useful thank you, if I wanted to remove the no follow attribute in its entirety as we have set an if statement so only administrators have access to the WYSIWYG editor I thought I would simply be able to remove the "nofollow" attribute from qa_html_convert_urls(...) however this hasn't seemed to work, any thoughts?
asked Mar 23, 2011 in Q2A Core by Remove the nofollow attribute?
this did not work for me, can you show me what I did wrong in the code:

This is what I have now:
function qa_html_convert_urls($html, $newwindow=false)
    Return $html with any URLs converted into links (with nofollow and in a new window if $newwindow)
    URL regular expressions can get crazy: http://internet.ls-la.net/folklore/url-regexpr.html
    So this is something quick and dirty that should do the trick in most cases
        return trim(preg_replace('/([^A-Za-z0-9])((http|https|ftp):\/\/([^\s&<>"\'\.])+\.([^\s&<>"\']|&amp;)+)/i', '\1<A HREF="\2" rel="nofollow"'.($newwindow ? ' target="_blank"' : '').'>\2</A>', ' '.$html.' '));
 // remove nofollow for my links
    $search = '/href="http:\/\/YOURDOMAIN\/([^"]*)" rel="nofollow"/i';
    $replace = 'href="http://YOURDOMAIN/\1"';       
    $html = trim( preg_replace($search, $replace, $html) );
    return $html;

This apparently does not work.