How to Insert a Link in a WHMCS Language Variable

WHMCS allows you to customise the text displayed in the Client Area by using language overrides. In some cases, you may want to include an HTML link directly inside a WHMCS language variable—for example, to point customers to a knowledgebase article, an external website, or a specific page of your Client Area.

This can easily be done by adding the appropriate HTML code to your WHMCS language override file.

Adding an HTML Link to a WHMCS Language Variable

Suppose you want to customise a language variable and include a clickable link in its text.

You can use the following syntax:

$_LANG['languagevariable'] = "Hello. <a href=\"https://www.mydomain.com/\">This is a link</a>. Do you like it?";

The resulting text displayed by WHMCS will look like this:

Hello. [This is a link]. Do you like it?

where This is a link will point to https://www.mydomain.com/.

Why Are the Quotes Escaped?

In the example above, the PHP string is enclosed in double quotes:

$_LANG['languagevariable'] = " ... ";

The HTML <a> element also normally uses double quotes around the URL:

<a href="https://www.mydomain.com/">

Because those quotation marks appear inside a PHP string that is already delimited by double quotes, they need to be escaped with a backslash:

href=\"https://www.mydomain.com/\"

Without escaping them, PHP would interpret the quotation mark as the end of the string, resulting in invalid PHP syntax.

An Easier Alternative: Use Single Quotes in the HTML

You can also avoid escaping the quotation marks by using single quotes for the HTML attributes:

$_LANG['languagevariable'] = "Hello. <a href='https://www.mydomain.com/'>This is a link</a>. Do you like it?";

Both approaches produce the same HTML output.

Opening the Link in a New Tab

If you want the link to open in a new browser tab, you can add the target="_blank" attribute:

$_LANG['languagevariable'] = "Hello. <a href=\"https://www.mydomain.com/\" target=\"_blank\" rel=\"noopener noreferrer\">This is a link</a>. Do you like it?";

The rel="noopener noreferrer" attribute is recommended when using target="_blank".

Use WHMCS Language Overrides Instead of Editing Core Language Files

When customizing WHMCS language strings, you should use a language override file rather than modifying the original WHMCS language files.

For example, for the English language you can add your custom language variables to:

/lang/overrides/english.php

A typical override file could contain:

<?php

$_LANG['languagevariable'] = "Hello. <a href=\"https://www.mydomain.com/\">This is a link</a>. Do you like it?";

Using language overrides makes your WHMCS customisations easier to maintain and prevents them from being overwritten when WHMCS is updated.

Complete Example

Here is a simple WHMCS language override containing a clickable link:

<?php

$_LANG['languagevariable'] = "For more information, please <a href=\"https://www.mydomain.com/help/\">read our documentation</a>.";

This technique can be useful whenever you need to insert HTML links into WHMCS language variables while keeping your text customisations inside the standard WHMCS language override system.

Leave a Reply 0

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