feat: emit hreflang x-default with multiple translations#1
Closed
apermo wants to merge 1 commit into
Closed
Conversation
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.
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
MslsOutput::get_alternate_links()only emitted anhreflang="x-default"alternate when asingle translation existed. With two or more translations — the normal multilingual case —
x-default was dropped and only language-specific alternates were returned.
x-defaultis the fallback search engines use when no otherhreflangmatches the visitor'slocale; Google and the W3C recommend it for multilingual pages. This emits it in the
multi-alternate case too.
How
$defaultthrough the existingmsls_output_get_alternate_links_defaultfilter and prepend it to the alternates.''from that filter suppresses x-default (opt-out). Single-translation behaviouris unchanged.
Tests
test_get_alternate_links_two_urlto assert the x-default alternate is present.test_get_alternate_links_x_default_suppressedcovering the empty-string opt-out.phpunitgreen (5/5 for alternate-links),phpcs(PHPCompatibility) clean,phpstanreportsno new errors in
MslsOutput.Refs