Problem
MslsOutput::get_alternate_links() only outputs an hreflang="x-default" alternate when
exactly one linked translation exists:
if ( 1 === count( $arr ) ) {
return apply_filters( self::MSLS_ALTERNATE_LINKS_DEFAULT_HOOK, $default );
}
$arr = (array) apply_filters( self::MSLS_ALTERNATE_LINKS_ARR_HOOK, $arr );
return implode( PHP_EOL, $arr );
When two or more translations exist — the normal multilingual case — x-default is dropped and
only the language-specific alternates are returned.
x-default is the fallback search engines use when no other hreflang matches the visitor's
locale (typically a language selector or the default-region page). Google and the W3C recommend
including it for multilingual pages, so omitting it precisely when several languages exist is the
opposite of the recommended behaviour.
Proposed fix
In the multi-alternate branch, also emit the already-computed $default (x-default) link, run
through the existing msls_output_get_alternate_links_default filter so it stays customisable
and can be suppressed by returning an empty string. Additive and backward compatible.
Acceptance criteria
- A page with ≥2 translations outputs an
hreflang="x-default" alternate alongside the
language-specific ones.
- Returning
'' from msls_output_get_alternate_links_default suppresses x-default.
- Single-translation behaviour is unchanged.
Problem
MslsOutput::get_alternate_links()only outputs anhreflang="x-default"alternate whenexactly one linked translation exists:
When two or more translations exist — the normal multilingual case —
x-defaultis dropped andonly the language-specific alternates are returned.
x-defaultis the fallback search engines use when no otherhreflangmatches the visitor'slocale (typically a language selector or the default-region page). Google and the W3C recommend
including it for multilingual pages, so omitting it precisely when several languages exist is the
opposite of the recommended behaviour.
Proposed fix
In the multi-alternate branch, also emit the already-computed
$default(x-default) link, runthrough the existing
msls_output_get_alternate_links_defaultfilter so it stays customisableand can be suppressed by returning an empty string. Additive and backward compatible.
Acceptance criteria
hreflang="x-default"alternate alongside thelanguage-specific ones.
''frommsls_output_get_alternate_links_defaultsuppresses x-default.