• Resolved rozprufacz

    (@3242fwefe)


    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:

    1. 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.
    2. 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.
    3. 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.

    • This topic was modified 2 months, 2 weeks ago by rozprufacz.
    • This topic was modified 2 months, 2 weeks ago by rozprufacz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @3242fwefe,

    Thank you so much for getting in touch.

    Sorry, but modifying the frontend’s HTML tags like H1 upon changing the filter is completely out of the scope of our plugin’s support. This customization should be managed via the theme level. We can only assist you in modifying the existing elements from our plugin such as the Canonical URL.

    Here’s the base filter code for that:

    /**
    * Allow changing of the canonical URL.
    *
    * @param string $canonical The canonical URL.
    */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    return $canonical;
    });

    For us to assist you in creating the correct code for the canonical URL, please share some example filter URLs and the expected canonical URL. 

    Looking forward to helping you.

    Thread Starter rozprufacz

    (@3242fwefe)

    Thank you for your response.

    I’m working with a local WordPress installation, so I’m unable to provide a live URL. However, here’s an example URL from my local setup:

    Local URL:
    local/kategoria-produktu/sruby-do-kol/?filter_gwint=12x1-25%2C14x1-5&query_type_gwint=or

    Expected Canonical URL:
    local/kategoria-produktu/sruby-do-kol/?filter_gwint=12×1-25&query_type_gwint=or

    I’d appreciate any assistance in modifying the canonical URL as needed. Please let me know how I can adjust the code for this.

    Looking forward to your guidance!

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @3242fwefe,

    You can use the following filter to add self-referencing canonical URL to the filter pages:

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    $current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    return $current_url;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.