How to set the Canonical URL to the first selected filter in WooCommerce
-
Hello,
I want the canonical URL to always point to the first selected filter in the URL, and I would like to achieve the following:
- Once the first filter is selected:
- A dedicated H1 tag should be generated based on the value of the first selected filter (e.g., if the filter is “Brand: Nike”, the H1 tag should display “Nike”).
- A dedicated description related to this filter should also be shown.
- When I select additional filters (e.g., after selecting the first filter, I choose another filter like “Size: Medium”):
- The H1 tag and the description should not change.
- The page should display products matching all selected filters, but the URL should not change to include the additional filter parameters.
- The additional filters should be handled exclusively via JavaScript to modify the displayed products on the page. The URL will not change, and no new parameters (such as
filter_size=medium
) will be added to the URL. - The H1 and description should remain the same as for the first filter, and the display of the products should update based on the combination of filters, but without affecting the URL or the meta tags.
- The canonical URL should continue to point to the first selected filter, regardless of how many additional filters I select.
Summary of Expected Behavior:
- The first selected filter controls the main H1 tag and description.
- Additional filters do not generate new URLs or URL parameters. They are handled via JavaScript to update the displayed products.
- The canonical tag always points to the first selected filter’s URL.
- The H1 tag and description remain the same after selecting additional filters.
This setup ensures that the SEO structure remains consistent, with relevant content for the user, while preventing unnecessary URL parameter changes and avoiding issues with duplicate content.
- Once the first filter is selected:
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.