Our Help Portal

Troubleshooting Support Articles
Searchable Help Information Repository
Self-Service Resources How-Tos
Technical Customer Walkthroughs   Browse All Knowledge ! ....

Get Prices Learn More

Breaking

< All Topics
Print

How to add Canonical Tags in WHMCS for SEO

Canonical tags play a crucial role in Search Engine Optimization (SEO) by helping search engines identify the preferred version of a page when multiple URLs lead to similar or identical content. In the context of WHMCS, implementing canonical tags is essential to avoid issues related to duplicate content and to consolidate the SEO value of your pages. By specifying the canonical URL, you guide search engines in understanding the primary source of your content and optimize your site’s visibility in search results.

Importance of Canonical Tags:

Canonical tags are HTML elements used to prevent duplicate content issues on a website, particularly when multiple URLs may lead to the same or very similar content. Search engines use canonical tags to identify the preferred version of a page, consolidating the ranking signals for that content.

The main reasons for using canonical tags include:

  1. Avoiding Duplicate Content: Canonical tags help search engines understand the primary URL for a piece of content, preventing the same content from being indexed multiple times under different URLs.
  2. Consolidating Page Authority: By specifying a canonical URL, you consolidate the SEO value (page authority, backlinks, etc.) to a single version of the content, enhancing its search engine ranking.

Adding Canonical Tags in WHMCS:

Here’s how to add a canonical tag in WHMCS, specifically using the corrected Smarty code provided earlier:

1. Identify the Template Files:

Determine the template files you want to modify, typically the header template.

2. Locate the Header Template:

Access your WHMCS installation files and navigate to the templates directory. Identify and open the header template file.

3. Edit the Header Template:

Add the following corrected Smarty code to dynamically generate the canonical URL:

<head>
<!– Other head elements –>
{capture assign=canonicalUrl}{if $smarty.server.HTTPS == ‘on’}https://{else}http://{/if}{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}{/capture}
<link rel=”canonical” href=”{$canonicalUrl}” />
</head>

Explanation of the Code:

  • {capture assign=canonicalUrl}: This Smarty tag captures the value generated within the block and assigns it to the variable named canonicalUrl.
  • {if $smarty.server.HTTPS == 'on'}https://{else}http://{/if}: This checks whether the current page is served over HTTPS or HTTP and includes the appropriate protocol in the URL.
  • $smarty.server.HTTP_HOST: This fetches the current host (domain) of the website.
  • $smarty.server.REQUEST_URI: This retrieves the request URI, including any query parameters, of the current page.
  • <link rel="canonical" href="{$canonicalUrl}" />: This HTML code generates the canonical tag using the dynamically captured URL.

4. Save and Upload:

Save the changes to the header template file and upload it back to the templates directory on your server.

5. Test:

Visit different pages on your WHMCS site and view the page source to ensure that the canonical tag is dynamically generated for each page.

By incorporating canonical tags into your WHMCS templates, you enhance your website’s SEO practices, helping search engines understand the structure of your content and contributing to improved search result rankings. This implementation provides a valuable addition to your knowledge base, empowering users to optimize their WHMCS installations for search engine visibility.

Categories