From 85c3b1096b42934fdc2cb4c943bd0313bd84d6fa Mon Sep 17 00:00:00 2001 From: Nic Horstmeier Date: Mon, 5 Apr 2021 19:52:35 -0500 Subject: [PATCH] UPDATE generate canonical via MetaComponents This replaces using the `MetaTags` method as replacing or removing a canonical requires string manipulation vs unsetting an array key, and is preferred. --- code/Model/VirtualPage.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/code/Model/VirtualPage.php b/code/Model/VirtualPage.php index ab06d63b..b0713a25 100644 --- a/code/Model/VirtualPage.php +++ b/code/Model/VirtualPage.php @@ -134,23 +134,22 @@ class VirtualPage extends Page } /** - * For VirtualPage, add a canonical link tag linking to the original page - * See TRAC #6828 & http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394 - * - * @param boolean $includeTitle Show default -tag, set to false for custom templating - * @return string The XHTML metatags + * @return array */ - public function MetaTags($includeTitle = true) + public function MetaComponents() { - $tags = parent::MetaTags($includeTitle); + $tags = parent::MetaComponents(); + $copied = $this->CopyContentFrom(); if ($copied && $copied->exists()) { - $tags .= HTML::createTag('link', [ - 'rel' => 'canonical', - 'href' => $copied->Link() - ]); - $tags .= "\n"; + $tags['canonical'] = [ + 'attributes' => [ + 'rel' => 'canonical', + 'content' => $copied->AbsoluteLink(), + ], + ]; } + return $tags; }