Skip to content

fix: update canonical tag on AJAX navigation - #97

Open
ahuininga-orisha wants to merge 1 commit into
developfrom
fix/220254-ajax-canonical-pagination
Open

fix: update canonical tag on AJAX navigation#97
ahuininga-orisha wants to merge 1 commit into
developfrom
fix/220254-ajax-canonical-pagination

Conversation

@ahuininga-orisha

Copy link
Copy Markdown
Collaborator

Companion PR to EmicoEcommerce/Magento2Tweakwise#389.

The Hyva theme uses its own inline vanilla JS implementation in navigation-form.phtml (no RequireJS). Without this change the canonical tag would not be updated after AJAX navigation on Hyva storefronts, even with the main module's fix applied.

Changes:

  • src/view/frontend/templates/layer/navigation-form.phtml — adds ajaxUpdateCanonical(canonical) method and calls it in the fetch() success handler. Updates href on the existing <link rel="canonical"> tag if present; does nothing if no canonical tag exists.

How to test

Scenario 1 — AJAX navigation updates canonical (Hyva)

  1. Enable Hyva theme. Set tweakwise/layered/enabled = 1, tweakwise/layered/ajax_filters = 1, catalog/seo/category_canonical_tag = 1, tweakwise/seo/paginated_canonical_enabled = 1. Run cache:clean and redeploy static content.
  2. Open a category page on the Hyva storefront.
  3. Inspect <link rel="canonical"> in DevTools — note the initial value.
  4. Apply a filter. After the AJAX response, canonical should reflect the current filtered URL.
  5. Navigate to page 2. Canonical should include ?p=2.

Scenario 2 — No canonical tag present, nothing added

  1. Set catalog/seo/category_canonical_tag = 0. Run cache:clean.
  2. Load a category page — confirm no canonical in <head>.
  3. Apply a filter via AJAX — confirm no canonical is inserted.

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