+4 votes
in CMS Tips by (17.9k points)

In the Vanilla forums discussion, I found that even internal links have "rel" => "nofollow noreferrer ugc". I do not want "nofollow" for internal links. It should be applicable only for external links. 

How to delete "rel" => "nofollow noreferrer ugc" for internal links? Is there any plugin for this?

1 Answer

+2 votes
by (14.6k points)

Assuming that most of the contents are generated by users in Vanilla forums, it's a good idea to have "rel" => "nofollow noreferrer ugc" for links. You never know what types of contents spammers can post with bad links. However, I think the internal links should not have "rel" => "nofollow noreferrer ugc".

I am not sure if there is a plugin for removing "nofollow" for internal links. But you can make a small change in one code, which will fix the issue.

Here are the changes that you need to make in "library/Vanilla/Formatting/Quill/Formats/Link.php":

Open the file in any editor and search for "protected function getAttributes()" and make the following changes:

From

protected function getAttributes(): array {

     $sanitizedLink = \Gdn_Format::sanitizeUrl(htmlspecialchars($this->currentOperation["attributes"]["link"]));

     return [

         "href" => $sanitizedLink,

         "rel" => "nofollow noreferrer ugc",

     ];

 }

to

protected function getAttributes(): array {

$sanitizedLink = \Gdn_Format::sanitizeUrl(htmlspecialchars($this->currentOperation["attributes"]["link"]));

$hosting_domain_name = "your_domain_name";

if (strpos($sanitizedLink, $hosting_domain_name) !== false){

return [

    "href" => $sanitizedLink,

    //"rel" => "nofollow noreferrer ugc",

];

}else{

return [

    "href" => $sanitizedLink,

    "rel" => "nofollow noreferrer ugc",

];

}

}

Replace "your_domain_name" with your real domain name in the above code. Here, I am just checking whether the link contains the hosting domain name. If the domain name is present, it means it's an internal link, so do not set rel to "nofollow noreferrer ugc". If it's an external domain, keep "rel" => "nofollow noreferrer ugc".

Save the file, and you are all set. Now the internal links will not have "rel" => "nofollow noreferrer ugc". You can check it by viewing the source in any browser.


...