The PSR-14 event \TYPO3\CMS\Frontend\Event\ModifyHrefLangTagsEvent is available to alter the hreflang tags just before they get rendered.

The class \TYPO3\CMS\Seo\HrefLang\HrefLangGenerator (identifier typo3-seo/hreflangGenerator) is also available as an event. Its purpose is to provide the default hreflang tags. This way it is possible to register a custom event listener after or instead of this implementation.


With after and before, you can make sure your own listener is executed after or before the given identifiers.



namespace MyVendor\MyExtension\Frontend\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\ModifyHrefLangTagsEvent;

    identifier: 'my-extension/cache-timeout',
    after: 'typo3-seo/hreflangGenerator',
final readonly class MyEventListener
    public function __invoke(ModifyHrefLangTagsEvent $event): void
        $hrefLangs = $event->getHrefLangs();
        $request = $event->getRequest();

        // Do anything you want with $hrefLangs
        $hrefLangs = [
            'en-US' => '',
            'nl-NL' => '',

        // Override all hrefLang tags

        // Or add a single hrefLang tag
        $event->addHrefLang('de-DE', '');

New in version 13.0

The PHP attribute \TYPO3\CMS\Core\Attribute\AsEventListener has been introduced to tag a PHP class as an event listener. Alternatively, or if you need to be compatible with older TYPO3 versions, you can also register an event listener via the Configuration/Services.yaml file. Switch to an older version of this page for an example or have a look at the section Implementing an event listener in your extension.


class ModifyHrefLangTagsEvent
Fully qualified name

Listeners to this event will be able to modify the hreflang tags that will be generated. You can use this when you have an edge case language scenario and need to alter the default hreflang tags.

getHrefLangs ( )
getRequest ( )
setHrefLangs ( array $hrefLangs)

Set the hreflangs. This should be an array in format:

    'en-US' => '',
    'nl-NL' => ''
param $hrefLangs

the hrefLangs

addHrefLang ( string $languageCode, string $url)

Add a hreflang tag to the current list of hreflang tags

param $languageCode

The language of the hreflang tag you would like to add. For example: nl-NL

param $url

The URL of the translation. For example: