Skip to content

fix(archive): no home_url fallback for tax/query#582

Merged
lloc merged 4 commits intolloc:masterfrom
apermo:fix/190-archive-hreflang-switcher
Mar 19, 2026
Merged

fix(archive): no home_url fallback for tax/query#582
lloc merged 4 commits intolloc:masterfrom
apermo:fix/190-archive-hreflang-switcher

Conversation

@apermo
Copy link
Contributor

@apermo apermo commented Mar 14, 2026

Summary

  • Override get_permalink() in MslsOptionsTax and MslsOptionsQuery to return empty string instead of falling back to home_url('/') when no translation exists
  • Change is_null() to empty() in MslsOutput::get_alternate_links() to also catch empty strings
  • Add empty($url) guard in MslsOutput::get() to skip blogs with no valid URL

Test plan

  • composer phpunit — all 393 tests pass
  • composer phpstan — no new errors
  • DDEV multisite: category archive shows correct hreflang links (or omits untranslated)

Closes #190


Authored with Claude Code

apermo added 2 commits March 14, 2026 22:44
Verify taxonomy/query archives don't fall back
to home_url and empty URLs are skipped in output.
Override get_permalink() in MslsOptionsTax and
MslsOptionsQuery to return empty string instead
of falling back to home_url('/').
Skip empty URLs in MslsOutput::get() and
get_alternate_links().

Closes lloc#190
@apermo apermo requested a review from lloc as a code owner March 14, 2026 21:49
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves an issue where untranslated taxonomy or query archives would incorrectly fall back to the site's home URL, leading to invalid hreflang links. The changes introduce more robust URL handling by ensuring that permalink generation explicitly returns an empty string when no translation is available and by adding checks to skip processing any empty URLs during output generation.

Highlights

  • MslsOptionsTax and MslsOptionsQuery: Overrode get_permalink() to return an empty string instead of falling back to home_url('/') when no translation exists.
  • MslsOutput::get_alternate_links(): Changed is_null() to empty() to also catch empty strings for URLs.
  • MslsOutput::get(): Added an empty($url) guard to skip blogs with no valid URL.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • includes/MslsOptionsQuery.php
    • Introduced a get_permalink method to provide a filtered permalink, returning an empty string if no translation is found.
  • includes/MslsOptionsTax.php
    • Introduced a get_permalink method to provide a filtered permalink, returning an empty string if no translation is found.
  • includes/MslsOutput.php
    • Added a check to skip processing blogs if their URL is empty within the get method.
    • Updated the get_alternate_links method to use empty() instead of is_null() for URL validation, ensuring empty strings are also handled.
  • tests/phpunit/TestMslsOptionsQuery.php
    • Added a new test case to verify that get_permalink returns an empty string when no translation is available.
  • tests/phpunit/TestMslsOptionsTax.php
    • Added test cases to verify get_permalink returns an empty string for untranslated items and the correct URL when a translation exists.
  • tests/phpunit/TestMslsOutput.php
    • Added test cases to ensure get_alternate_links correctly handles empty URLs and that the get method skips blogs with empty URLs.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses the issue of get_permalink() falling back to the home URL for taxonomy and query archives by overriding the method in MslsOptionsTax and MslsOptionsQuery. The related changes in MslsOutput to handle potentially empty URLs are also correct. The new tests effectively cover these changes. My main feedback is about code duplication in the new get_permalink methods, which could be refactored for better maintainability. Please see the specific comments for details.

Copy link
Owner

@lloc lloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to the MSLS. ❤️

@lloc lloc merged commit b4753e4 into lloc:master Mar 19, 2026
1 check passed
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.

Archive hreflang and switcher not working

2 participants