Add HTTP Responsive Headers to homepage of WHMCS

56 Views Asked by At

I am trying to add/overwrite the HTTP Responsive Headers to the WHMCS public homepage. Using PHP they should look like this:

header("Cache-Control: public, max-age=10800, must-revalidate"); // HTTP 1.1.
header("Pragma: cache"); // HTTP 1.0.

However, in smarty 3+ the use of php tags is no longer supported.

I have tried the following on the header.tpl file but failed:

{if $templatefile == 'homepage'}
  header("Cache-Control: public, max-age=86400, must-revalidate"); // HTTP 1.1.
  header("Pragma: cache"); // HTTP 1.0.
{/if}

How would I add these headers to the header.tpl file so they are read as PHP? Thanks.

1

There are 1 best solutions below

0
M. Haseeb Akhtar On

As I suggested in the comments, you can do this by using ClientAreaHeadOutput hook, like:

add_hook('ClientAreaHeadOutput', 1, function ($vars) {
    // Check if the current file name is index aka home
    if ($vars['filename'] == 'index') {
        header("Cache-Control: public, max-age=10800, must-revalidate"); // HTTP 1.1.
        header("Pragma: cache"); // HTTP 1.0.
    }
});

You can also use App::getCurrentFilename() instead of $vars['filename'] to get current file name.