Bug #87760
closedEpic #89797: HrefLang / Canonical issues
Option to remove params from canonical tag
0%
Description
I have a page with news plugin and pagination.
Each pagination url and also the canonical tag looks like:
- example.com/news/2/
- example.com/news/3/
- example.com/news/.../
Currently there is no possibility to remove the tx_news_pi1[@widget_0][currentPage] param from the canonical tag.
I've tested the behaviour with and without RouteEnhancers, no changes.
The CanonicalGenerator uses a function "getParamsToExcludeForCanonicalizedUrl" in "TYPO3\CMS\Frontend\Utility\CanonicalizationUtility" to determine which params should be removed from the canonical tag.
But at the moment this only removes params wich should be ignored for chash calculation - but this is no solution for pagination widget.
Updated by Richard Haeser over 5 years ago
- Status changed from New to Needs Feedback
Why do you want to remove the page parameter? Paginated pages shouldn’t have a canocial to the first page and that is what happens when you remove the parameter.
See https://yoast.com/pagination-seo-best-practices/ for more information
Updated by Patrick Fiedorowicz over 5 years ago
Richard Haeser wrote:
Why do you want to remove the page parameter? Paginated pages shouldn’t have a canocial to the first page and that is what happens when you remove the parameter.
You are right, Google said that the canonical tag should also include paginated pages.
But most seo tools complain about duplicate titles of the news list and paginated pages. So I would prefer to remove them from canonical tag.
But I can give you another example:
If you use news with categories (article can be related to multiple categories) and use them for filtering, you have to remove the category parameter from canonical tag to prevent duplicate content.
Updated by Richard Haeser over 5 years ago
- Status changed from Needs Feedback to New
Updated by Christoph Hendreich over 5 years ago
- Related to Feature #88242: Make canonical optional added
Updated by Lidia Demin about 5 years ago
Example use case, where parameters shouldn't be added to canonical tag¶
There is an element that displays individually share-able content blocks. Therefore parameters are attached to the page url the content block is displayed on. If such a content block is shared, the og-tags fetched from the parametric url contain information of the content block and not of the page it's on, but the canonical tag should be the same as the target page still displays the same content.
Example code:
<f:for each="{ContentBlocks}" as="ContentBlock">
<div id="content-block-1">
<!-- content block content here -->
<a href="https://www.facebook.com/sharer/sharer.php?u={f:uri.action(
pluginName: 'ContentBlockSlider',
controller: 'ContentBlock',
action: 'ContentBlockSlider',
arguments: '{contentBlock: contentBlock}', absolute: 1
)}">Share me</a>
</div>
</f:for>
The controller action then overrides the according meta tags. if a $contentBlock argument was provided.
There were several use cases where we had to use this approach to share different contents on one page.
Updated by Richard Haeser almost 5 years ago
- Status changed from New to Closed
For both cases you could use the hook in TYPO3 v9 or the PSR-14 event ModifyUrlForCanonicalTagEvent in v10.2+
You can add your own logic and set the canonical link you want. Be aware that the canonical is using all relevant parameters that are used for cHash calculation as well. If a parameter is not necessary for a canonical url, you also might want to check if it is necessary for cHash calculation.
Updated by Matthias Kappenberg about 2 years ago
Try to add your get Vars to:
$GLOBALS['TYPO3_CONF_VARS']['FE']['cacheHash']['excludedParameters']
list, worked in my case (v10 and v11).