Sun. Jul 12th, 2020

SharkServers Blog

DMCA Ignored Hosting

This Is War! WHMCS Canonical Tag

2 min read

WHMCS has historically been known as being a nightmare to do SEO for. As we’re currently in process of doing proper SEO both on- and off-site, one of the things for the on-site part is meta tags. Manually, even the title and description tags are hard to work with, but that can be easily resolved by using a free WHMCS addon called SEO Manager. That, however, doesn’t solve the issue with the canonical tag.

What Is Canonical Tag And Why Should I Care?

Due to the way WHMCS is coded, a lot of pages will be considered duplicates. This is because the same page passes on variables, such as language, currency and so on – within the URL. Search engines don’t like duplicate content, so the canonical tag is a way to tell them that the supposedly duplicate page is, in fact, a version of some other page. This is very important, as duplicate content (even though just perceived as such by search engines) can negatively affect SERPs.

So what do we do?

There are very few discussions on WHMCS community pages regarding this, so we’re left alone to figure out how to implement this. Once we do, we’ll provide an update, as we know that we are not the only ones looking for a solution for this issue.

Update

We finally figured it out. As per the linked posts above yes, you need a hook. However, the suggested code was throwing the wrong values, and at some point didn’t seem to work at all. That said, we still figured it out, so this is what we came up with. Enjoy!

/includes/hooks/canonicaltag.php

<?php
if (!defined("WHMCS"))
    die("This file cannot be accessed directly");

add_hook('ClientAreaHeadOutput', 1, function($vars)
{
    
	$SystemURL = 'https://www.sharkserve.rs';
	$url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	$url = strtok($url, '?');
    return <<<HTML
    <link rel="canonical" href="{$url}"/>
HTML;
});

Leave a Reply

Your email address will not be published. Required fields are marked *