page_canonical_metatag

Filter Hook Meta Tags

Filter the canonical meta tag.

Parameters

$url

(string) canonical URL

$params

(array) associative array with contextual data

You need to have a working knowledge of Hooks before you get started.

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
  // For JReviews 3.x and earlier use dd instead of fwd_dd
  // fwd_dd($url, $params);
  
  return $url;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

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

  • /services/metatags/metatags.php
  • /cms_compat/joomla/includes/plugins/jreviews.php
  • /cms_compat/joomla/includes/plugins/jreviews-joomla4.php