...
Admin settings can be found under Stores -> Configuration -> MageSuite -> SEO
tab.
...
Settings:
Name | Value | Comment |
---|---|---|
Canonical Tag For Other Pages | Yes/No | Enables canonical tag for pages which Magento doesn't support out of the box like CMS ones. Read more. |
Backend
Note |
---|
Backend documentation in progress |
view/frontend/templates/canonical.phtml
Code Block |
---|
<?php
$canonicalUrl = $block->getCanonicalUrl();
if ($canonicalUrl):
?>
<link rel="canonical" href="<?= $canonicalUrl; ?>">
<?php
endif; |
vendor/creativestyle/magesuite-seo-canonical/Block/Canonical.php:25
Code Block |
---|
class Canonical extends \Magento\Framework\View\Element\Template
{
protected $_template = 'MageSuite_SeoCanonical::canonical.phtml';
.....
public function getCanonicalUrl()
{
return $this->canonicalUrl->getCanonicalUrl();
}
} |
vendor/creativestyle/magesuite-seo-canonical/Service/CanonicalUrl.php:33
Code Block |
---|
class CanonicalUrl
{
const SEO_CANONICAL_TAG_PATH = 'seo/configuration/canonical_tag_enabled';
.....
public function getCanonicalUrl()
{
if (!$this->isEnabled()) {
return null;
}
$canonicalUrl = $this->urlBuilder->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
return $this->formatCanonicalUrl($canonicalUrl);
}
private function formatCanonicalUrl($canonicalUrl)
{
$urlWithoutParams = $this->stripGetParams($canonicalUrl);
if ($this->isHomepageWithStoreCodeInPath($urlWithoutParams)) {
return $urlWithoutParams;
}
return rtrim($urlWithoutParams, '/');
}
private function stripGetParams($canonicalUrl)
{
return strtok($canonicalUrl, '?');
}
} |
Frontend
Frontend template for canonical URLs is located under Creativestyle_SeoCanonicalExtension::canonical.phtml
It uses getCanonicalUrl()
in order to display a canonical url.
...