Generate the canonical URL dynamically using the site's configured base URL (SYS_URL) + the current
request path ($_SERVER['REQUEST_URI'])
1. includes/functions.php — Add canonical generation in page_header() (after line 7282)
After the existing $smarty->assign('page_image', $image);, add:
PHP:
/* generate canonical URL */
$page_canonical = '';
if (isset($_SERVER['REQUEST_URI'])) {
$request_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if ($request_path !== null && $request_path !== '') {
$skip_prefixes = ['/admincp', '/modcp', '/admin.php', '/moderator.php'];
$is_control_panel = false;
foreach ($skip_prefixes as $prefix) {
if (strpos($request_path, $prefix) === 0) {
$is_control_panel = true;
break;
}
}
if (!$is_control_panel) {
$page_canonical = SYS_URL . $request_path;
}
}
}
$smarty->assign('page_canonical', $page_canonical);
Key decisions:
if (strpos($request_path, $prefix) === 0) {
$is_control_panel = true;
break;
}
}
if (!$is_control_panel) {
$page_canonical = SYS_URL . $request_path;
}
}
}
$smarty->assign('page_canonical', $page_canonical);
2. content/themes/default/templates/_head.tpl — Add canonical tag (after line 26)
After <!-- OG-Meta -->, before <!-- Twitter-Meta -->:
Code:
<!-- Canonical -->
{if $page_canonical neq ''}
<link rel="canonical" href="{$page_canonical}" />
{/if}
<!-- Canonical -->
3. Add og:url in _head.tpl inside the OG-Meta block (after line 25)
Code:
<meta property="og:url" content="{if $page_canonical neq
''}{$page_canonical}{else}{$system['system_url']}{/if}" />
This helps social platforms (Facebook, etc.) identify the canonical URL for shared links.
This should do what you want; however, I have not tested the code within a script yet.