WHMCS SEO Code Complete Guide

Here is a collection of code items I’ve gathered for doing WHMCS SEO and ranking in SERP.

A lot of these I got from the WHMCS forums and googlin’ stuff. This guy Brian on the WHMCS forums is really good. So I wanted to properly link him here.

Another thing to note before we begin, I recommend at a minimum using the WHMCS friendly URLs, or full friendly.

Now let’s begin.

First let’s start with the easy ones. Go to your theme folder, find your active theme (I’m using a paid one) and insert this code in the header.tpl (/var/www/html/templates/NAME/header.tpl)

It will make sure crawling robots index your pages.

<meta name=”robots” content="index, follow">

WHMCS Product Group SEO

Now let’s configure meta title and descriptions for pages. I’ll start with the product groups. In the same “/var/www/html/templates/NAME/header.tpl” file add this:

{if ($gid)}
<title>{$LANG.pagetitle.configureproductdomain.$gid}</title>
<meta name="description" content="{$LANG.metadescription.configureproductdomain.$gid}" />
{/if>

That takes the page title and meta description you provide in a language file and apply a unique one per page. So now you’ll need to actually create those text variables in the language file under “/var/www/html/lang/overrides/english.php”

Note you’ll have to create the sub directory and file if it doesn’t exist. Here’s what you can add there. Notice how I got the number three in there. I got that by editing my product in WHMCS, and going to the link tab to grab the group id.

$_LANG['pagetitle']['configureproductdomain']['3'] = 'MY SEO TITLE';
$_LANG['metadescription']['configureproductdomain']['3'] = 'MY SEO META DESC';

If you want to add more, just get the group ID from other products, here’s another example added on to include in “/var/www/html/overrides/english.php”

$_LANG['pagetitle']['configureproductdomain']['5'] = 'MY SECOND TITLE';
$_LANG['metadescription']['configureproductdomain']['5'] = 'MY SECOND META DESC';

WHMCS Homepage SEO

Now let’s add some SEO to the homepage, go back to the same header.tpl for the homepage.

{if ($templatefile eq 'homepage')}
<title>{$LANG.pagetitle.homepage}</title>
<meta name="description" content="{$LANG.metadescription.homepage}" />
{/if>

Head back over to the “/var/www/html/lang/overrides/english.php” and add this

$_LANG['pagetitle']['homepage'] = 'MY HOMEPAGE TITLE';
$_LANG['metadescription']['homepage'] = 'MY HOMEPAGE META DESC';

WHMCS Checkout page SEO

Here’s code for the header.tpl you can use for the checkout page.

{if ($checkout)}
 <title>Checkout Order | CONTENT | COMPANYNAME</title>
{/if>

WHMCS Shopping Cart SEO

And now some misc. code for the product.

{if ($productinfo)}
<title>{$productinfo.name}</title>
{/if>
{if (!$inShoppingCart)}
<title>{$templatefile|capitalize}</title>
{/if>

WHMCS Knowledgebase and article SEO

Finally here’s what worked for me on the knowledgebase. You just need the KB article ID, which you can get from browsing to the page, in this case I am using friendly url with index.php so after I browse to the article I see:

https://www.DOMAIN.com/index.php/knowledgebase/1/ARTICLETITLE.html

So the “1” there is the article ID.

{if ($templatefile  eq 'knowledgebasearticle')}

<title> {$kbarticle.title} </title>
{if $kbarticle.id eq 1}
<meta name="description" content="DESC HERE" />
{/if}


{if $kbarticle.id eq 2}
<meta name="description" content="DESC HERE" />
{/if}


{if $kbarticle.id eq 3}
<meta name="description" content="DESC HERE" />
{/if}



{if $kbarticle.id eq 4}
<meta name="description" content="DESC HERE" />
{/if}

{if $kbarticle.id eq 6}
<meta name="description" content="DESC HERE" />
{/if}

{if $kbarticle.id eq 7}
<meta name="description" content="DESC HERE" />
{/if}

{if $kbarticle.id eq 8}
<meta name="description" content="DESC HERE" />
{/if}

{if $kbarticle.id eq 9}
<meta name="description" content="DESC HERE" />
{/if}
{/if>

WHMCS ARTICLE IN PRODUCT SEO

If you want to just add some custom paragraphs under product groups for SEO purposes, you can use this. First, we need to edit a different file, we must be under the cart template/ order form template. Mine is “/var/www/html/templates/MYTEMPLATE/products.tpl”. I wanted to add an article under products with a GID of 3. So I added this in towards the end:

{if ($gid == 3)}
<h2> My title of article </h2>
<p style="text-align:left"> MY PARAGRAPH</p>
{/if}

You can rinse and repeat that for multiple groups by adding different GID if statements. Again you can get the GID by editing the product in WHMCS, and switch to the links tab.

WHMCS Canonical SEO

Now for the canonical name, you can do this with the header.tpl file if you wanted, but I just went with something I had found that worked. Plus, it’s nice to show different methods.

To do this part, you’ll need to create a hook in WHMCS, here’s how to do that. Basically just create a name.php file under “/var/www/html/templates/NAME/hooks/”

I got this specific code from here.

Create a new file called canonical.php and save this code:

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

add_hook('ClientAreaHeadOutput', 1, function($vars)
{

        $SystemURL = 'https://YOURDOMAIN.com';
        $url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url = strtok($url, '?');
    return <<<HTML
    <link rel="canonical" href="{$url}"/>
HTML;
});

Now every page should have a canonical link that matches your root domain and thus preventing duplicate content in the search engine pages.

You can verify this by checking the HTML source of your page and it should look like this:

<link rel="canonical" href="https://www.X.com/index.php/store/category" />

WHMCS Twitter Card SEO

If you wanted to do some Google rich content for SEO, like twitter cards for example you can add this to the header.tpl

{if ($templatefile eq 'homepage')}
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="website" />
<meta property="og:title" content="meta title here" />
<meta property="og:description" content="meta desc here" />
<meta property="og:url" content="https://www.SITE.com/" />
<meta property="og:site_name" content="SITE.com" />
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@TWITTERUSERHERE" />
<meta name="twitter:label1" content="Cst. reading time">
<meta name="twitter:data1" content="0 minutes">
{/if>

WHMCS Rich Content SEO

Here’s some more rich content Google likes for SEO purposes, some JSON-LD data for reviews. If you aren’t familiar with Rich content check this out. In my case I added it to the homepage, but most people will probably add it under /var/www/html/templates/orderforms/NAME/products.tpl using the product group ID which is the same method we used in above for the article under the product group.

{if ($templatefile eq 'homepage')}
<script type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": "PRODUCT NAME",
  "image": "SOMEIMAGEURL.JPG",
  "description": "META DESC",
  "brand": {
    "@type": "Thing",
    "name": "MY COMPANY NAME"
  },
   "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": "4.3",
    "reviewCount": "3"
  },
  "offers": {
    "@type": "Offer",
    "priceCurrency": "USD",
    "price": "14.99",
         "availability": "InStock",
    "priceValidUntil": "2010-12-01",
    "url": "https://www.PRODUCTPAGE.COM/PRODUCT"
  },
  "review": {
  "@type": "Review",
  "author": "JOE.",
  "datePublished": "2010-12-019",
  "description": "THX",
  "name": "NAME OF REVIEW",
 "reviewRating": {
  "@type": "Rating",
  "bestRating": "5",
  "ratingValue": "4",
  "worstRating": "1"
  }
 }
}
</script>
{/if>

Once your rich content is added to the homepage, or any page really, you can test it with this google tool.

Another cool thing I found is if you just add this code below to any page, it will open a pop-up with all the available variables you can use. This is if you wanted more advanced items I did not cover. Just put this code on any “.tpl” page like “header.tpl”. Note you HAVE to remove it right after because EVERYONE will see the pop-up. It’s for debugging/testing only. In my case I did this in the KB article page for testing SEO, but again it works on any page.

{debug}

That’s it, now you should have at least some basic SEO done on your WHMCS deployment. Another thing you can do if you don’t like this is to just deploy a blog like wordpress on a separate hosting account/vps. You could also deploy it in the same hosting account or domain but I wouldn’t it just due to security issues.