Bug #103642
closedAlternate hreflang x-default
0%
Description
The meta tag "x-default" can currently only be changed by manually adjusting the order in the language array of the sites.yaml file. It is not possible to change the order in the backend.
The good news is that by changing the order, the correct x-default value is actually used in the frontend. In my case languageId: 2
languages:
- languageId: 2
enabled: true
title: Englisch
websiteTitle: fellow.dog
base: 'https://www.fellow.dog/'
locale: en_US.utf8
navigationTitle: English
direction: ''
fallbackType: strict
fallbacks: ''
flag: en-us-gb
deeplTargetLanguage: EN-US
- languageId: 0
enabled: true
title: Deutsch
base: 'https://www.darf-ich-mit.de/'
locale: de_DE.utf8
navigationTitle: Deutsch
direction: ''
flag: de
websiteTitle: ''
deeplTargetLanguage: DE
But now to the problem. Due to the change, my languageId 0 (German) is hidden in the backend when I want to edit pages. (see screenshot)
I have come across the problem with the x-default several times now, both privately and professionally, and would very much like to be able to adjust the x-default value in the sites config
The use of the EXT:cs_seo extension offers this feature, but only halfway, because the URLs for RouteEnhancers are not resolved. Therefore their feature is unfortunately unusable
Files
Updated by Mark Weisgerber 7 months ago
If you need a workaround (hardcoded and not based on the LanguageID) until there is something official:
Services.yaml:
Vendor\DarfIchMit\EventListener\ModifyHrefLangTagsEventListener:
tags:
- name: event.listener
identifier: 'vendor/darf-ich-mit/modify-href-lang-tags-event-listener'
event: 'TYPO3\CMS\Frontend\Event\ModifyHrefLangTagsEvent'
EventListener:
/**
* Manipulates the x-default entity
*/
class ModifyHrefLangTagsEventListener
{
/**
* Manipulates the x-default entity
*
*/
public function __invoke(ModifyHrefLangTagsEvent $event): void
{
if(isset($event->getHrefLangs()['en-US'])){
$event->addHrefLang('x-default', $event->getHrefLangs()['en-US']);
}
}
}
Updated by Mark Weisgerber 7 months ago
Updated by Stefan Bürk 7 months ago
- Status changed from New to Needs Feedback
TBH I have not tested it by myself, but the siteconfiguration allows to manual set
hreflang labels for a language. And the documentation states, that it can be used
to manually define the `x-default` language.
Granted, there is a note for 12.4 that this is retrieved from the locale, but as the href field is still there it may work to set it for the
whished language as `default` (or x-default`).
I could not see if you have tried that already.
Sorting the languages manually is not good, and languageId = 0 should always be the first one. It's technical the default language throughout TYPO3 and moving it away does not match the generic design and expectation - which confirms your issue after resorting it manually. I guess, all foreign language can be resorted, but leave languageId = 0 as first language per SiteConfiguration.
Updated by Georg Ringer 4 months ago
- Status changed from Needs Feedback to Closed
hey!
as you mentioned changing the options is not really a good way as it leads to unexpected results.
I propose that you use the event to modify the x-default option. We won't provide yet another checkbox in the core as the default is good enough and anything else depends on so many things? have also seen seo agencies which wanted the x-default to vanish and maybe a usecase could be that an editor is allowed to choose the correct language, ...
therefore please use the event and implement it in your site package or maybe as small extension and publish it.
if you don't agree, feel free to contact me via slack!