Attention
TYPO3 v12 has reached end-of-life as of April 30th 2026 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v12 here: TYPO3 ELTS.
ModifyUrlForCanonicalTagEvent
With the PSR-14 event TYPO3CMSSeo
the URL for the
href attribute of the canonical tag can be altered or
emptied.
New in version 12.4.9
The methods
get and
get have been added.
Example
Registration of the event in the Services.:
services:
# Place here the default dependency injection configuration
MyVendor\MyExtension\Seo\EventListener\MyEventListener:
tags:
- name: event.listener
identifier: 'my-extension/modify-url-for-canonical-tag'
Changing the host of the current request and setting it as canonical:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\Seo\EventListener;
use TYPO3\CMS\Seo\Event\ModifyUrlForCanonicalTagEvent;
final class MyEventListener
{
public function __invoke(ModifyUrlForCanonicalTagEvent $event): void
{
// Note: $event->getUrl() is dispatched with the empty string value ''
$currentUrl = $event->getRequest()->getUri();
$newCanonical = $currentUrl->withHost('example.com');
$event->setUrl((string)$newCanonical);
}
}