Skip to content

Commit f4c594a

Browse files
committed
Add canonical url tag
1 parent 6998880 commit f4c594a

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

Block/Archive/PostList.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ protected function _prepareLayout()
5555
$title = $this->_getTitle();
5656
$this->_addBreadcrumbs($title);
5757
$this->pageConfig->getTitle()->set($title);
58+
$this->pageConfig->addRemotePageAsset(
59+
$this->_url->getUrl(
60+
$this->getYear() . '-' . str_pad($this->getMonth(), 2, '0', STR_PAD_LEFT),
61+
\Magefan\Blog\Model\Url::CONTROLLER_ARCHIVE
62+
),
63+
'canonical',
64+
['attributes' => ['rel' => 'canonical']]
65+
);
5866

5967
return parent::_prepareLayout();
6068
}

Block/Author/PostList.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ protected function _prepareLayout()
4949
$this->_addBreadcrumbs($author);
5050
$this->pageConfig->addBodyClass('blog-author-' . $author->getIdentifier());
5151
$this->pageConfig->getTitle()->set($author->getTitle());
52-
//$this->pageConfig->setKeywords($author->getMetaKeywords());
53-
//$this->pageConfig->setDescription($author->getMetaDescription());
52+
$this->pageConfig->addRemotePageAsset(
53+
$author->getAuthorUrl(),
54+
'canonical',
55+
['attributes' => ['rel' => 'canonical']]
56+
);
5457
}
5558

5659
return parent::_prepareLayout();

Block/Category/View.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ protected function _prepareLayout()
5454
$this->pageConfig->getTitle()->set($category->getTitle());
5555
$this->pageConfig->setKeywords($category->getMetaKeywords());
5656
$this->pageConfig->setDescription($category->getMetaDescription());
57+
$this->pageConfig->addRemotePageAsset(
58+
$category->getCategoryUrl(),
59+
'canonical',
60+
['attributes' => ['rel' => 'canonical']]
61+
);
5762
}
5863

5964
return parent::_prepareLayout();

Block/Index.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ protected function _prepareLayout()
2626
$this->pageConfig->getTitle()->set($this->_getConfigValue('title'));
2727
$this->pageConfig->setKeywords($this->_getConfigValue('meta_keywords'));
2828
$this->pageConfig->setDescription($this->_getConfigValue('meta_description'));
29+
$this->pageConfig->addRemotePageAsset(
30+
$this->_url->getBaseUrl(),
31+
'canonical',
32+
['attributes' => ['rel' => 'canonical']]
33+
);
2934

3035
return parent::_prepareLayout();
3136
}

Block/Post/View.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ protected function _prepareLayout()
2828
$this->pageConfig->getTitle()->set($post->getTitle());
2929
$this->pageConfig->setKeywords($post->getMetaKeywords());
3030
$this->pageConfig->setDescription($post->getMetaDescription());
31+
$this->pageConfig->addRemotePageAsset(
32+
$post->getPostUrl(),
33+
'canonical',
34+
['attributes' => ['rel' => 'canonical']]
35+
);
3136
}
3237

3338
return parent::_prepareLayout();

0 commit comments

Comments
 (0)