Skip to content

Conversation

@rbcorrales
Copy link
Member

All Submissions:

Changes proposed in this Pull Request:

  • Add Link_Rewriter class to enqueue a frontend script that rewrites internal links.
  • Add new link-rewriter/index.js script:
    • Detects current brand from URL (?brand=brand-slug).
    • Rewrites all internal anchor tags to include the brand parameter if not already present.
    • Skips external links and links that already have a brand parameter.
  • Register and enqueue the script via Link_Rewriter::init() in Initializer.
  • Update webpack config to bundle linkRewriter and provide WordPress externals.

This helps preserve brand context through links as users navigate the site.

How to test the changes in this Pull Request:

  1. Verify that the Link Rewriter is initialized and its script is enqueued on the frontend.
  2. Verify that internal links on a page with a brand override are rewritten.
    • Visit a public page (for example, a post or an archive) and append ?brand=brand‑a (or a valid brand slug) to the URL.
    • Inspect the page (using your browser's dev tools) and locate internal anchor tags (for example, a link to another post or a category).
    • Confirm that the href attribute of these internal links is rewritten (i.e. ?brand=brand‑a is appended).
  3. Verify that links that are not internal are not rewritten.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

- Add `Link_Rewriter` class to enqueue a frontend script that rewrites internal links.
- Add new `link-rewriter/index.js` script:
  - Detects current brand from URL (`?brand=brand-slug`).
  - Rewrites all internal anchor tags to include the brand parameter if not already present.
  - Skips external links and links that already have a brand parameter.
- Register and enqueue the script via `Link_Rewriter::init()` in `Initializer`.
- Update webpack config to bundle `linkRewriter` and provide WordPress externals.

This helps preserve brand context through links as users navigate the site.
@rbcorrales rbcorrales requested a review from a team as a code owner May 21, 2025 15:55
- Expose current page brand from the backend via `wp_localize_script`
- Store and get the brand preference from the `np_preferred_brand` LS key
- Lint JS
return;
}

// Enqueue WordPress dependencies.
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary, if these scripts are listed as dependencies in the call on line 37?

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.

3 participants