page_canonical_metatag
Filter the canonical meta tag.
You need to have a working knowledge of Hooks before you get started.
Parameters
| Name | Type | Description |
|---|---|---|
$url |
parameter |
(string) canonical URL |
$params |
parameter |
(array) associative array with contextual data |
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
Clickfwd\Hook\Filter::add('page_canonical_metatag', function($url, $params)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($url, $params);
return $url;
});
Examples
Custom field driven canonicals in listing detail pages
This example allows using the URL value set in a custom field for the listing detail page canonical tag. This can be useful if for example you publish content that originated somewhere else, like a press release. Using the canonical references the original source, rather than creating a duplicate. The custom field used for the canonical URL needs to remain published, but can be de-activated from list and detail view so it's not visible on the page.
Clickfwd\Hook\Filter::add('page_canonical_metatag', function($url, $params)
{
if ($params['route'] !== "listing.detail") {
return $url;
}
$custom = $params['listing']['Field']['pairs']['jr_canonical']['value'][0] ?? null;
if (! $custom) {
return $url;
}
return $custom;
});
Source Files
/services/metatags/metatags.php/cms_compat/joomla/includes/plugins/jreviews.php/cms_compat/joomla/includes/plugins/jreviews-joomla4.php