Skip to content

Commit

Permalink
Merge pull request #2647 from muskie9/bugfix/virtualPageCanonical2637
Browse files Browse the repository at this point in the history
UPDATE generate canonical via MetaComponents
  • Loading branch information
dhensby authored May 14, 2021
2 parents 4e8c5e6 + 85c3b10 commit f230adc
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions code/Model/VirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,22 @@ public function ContentSource()
}

/**
* 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 <title>-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;
}

Expand Down

0 comments on commit f230adc

Please sign in to comment.