Skip to content

feat: emit hreflang x-default with multiple translations#1

Closed
apermo wants to merge 1 commit into
masterfrom
feature/hreflang-x-default
Closed

feat: emit hreflang x-default with multiple translations#1
apermo wants to merge 1 commit into
masterfrom
feature/hreflang-x-default

Conversation

@apermo
Copy link
Copy Markdown
Owner

@apermo apermo commented May 31, 2026

What

MslsOutput::get_alternate_links() only emitted an hreflang="x-default" alternate when a
single translation existed. With two or more translations — the normal multilingual case —
x-default was dropped and only language-specific alternates were returned.

x-default is the fallback search engines use when no other hreflang matches the visitor's
locale; Google and the W3C recommend it for multilingual pages. This emits it in the
multi-alternate case too.

How

  • In the multi-alternate branch, run the already-computed $default through the existing
    msls_output_get_alternate_links_default filter and prepend it to the alternates.
  • Returning '' from that filter suppresses x-default (opt-out). Single-translation behaviour
    is unchanged.

Tests

  • Updated test_get_alternate_links_two_url to assert the x-default alternate is present.
  • Added test_get_alternate_links_x_default_suppressed covering the empty-string opt-out.
  • phpunit green (5/5 for alternate-links), phpcs (PHPCompatibility) clean, phpstan reports
    no new errors in MslsOutput.

Refs

get_alternate_links() only returned an x-default alternate when a
single translation existed; with two or more it was dropped. x-default
is the recommended fallback for multilingual pages, so emit it in the
multi-alternate case too.

The x-default link runs through the existing
msls_output_get_alternate_links_default filter, so it stays
customisable and can be suppressed by returning an empty string.
Single-translation behaviour is unchanged.
@apermo
Copy link
Copy Markdown
Owner Author

apermo commented May 31, 2026

Superseded by the upstream PR lloc#641 (tracking issue lloc#640). Closing this fork-only PR; the branch stays as the head of the upstream PR.

@apermo apermo closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant