How to add self canonical url to facet pages?

#78855
  • Resolved Akshay
    Rank Math free

    Hey team,
    I am using Rankmath for my woocommerce site, When i use filters on archive page, the filter links get added to url
    Eg:
    wyx .com/wooden-table/?color-red&&Type-Leather

    Now I am trying to index these pages, by adding them in XML sitemap. And they are getting indexed. Everything is fine till here, until,there are a lot more products in the filter applied.

    So google is indexing the paginated pages too. And I don’t want that.
    wyx .com/wooden-table/?color-red&&Type-Leather%%page2

    So I want this filter page to be self canonicalized. Currently it get canonicalized to the root page i.e. wyx .com/wooden-table/
    But this deletes my purpose of having the page indexed.

    The canonical URL for this page and every paginated page after those filter are applied should be,
    wyx .com/wooden-table/?color-red&&Type-Leather

    What should be done?

    PS: I am using Premmerce filters. But If you can give me any solution for this problem with any other recommended plugin, I am ready to use that.

    PPS: YITH filters, Facetwp doesnot support this, had a chat with them!

Viewing 15 replies - 1 through 15 (of 15 total)
  • Michael Davis
    Rank Math pro

    Hello,

    Thank you for contacting Rank Math today.

    To noindex paginated pages, please enable the option in Rank math > Titles & Meta > Misc
    img

    Rank Math automatically adds a self canonical tag to your pages. To change this, you can customize the following filter to use the current URL as the canonical:

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

    Hope that helps you. Thank you.

    Akshay
    Rank Math free

    this did not served the purpose.

    I want my url, after filter is applied, to be self canonicalized.
    And the page 2 of the filter result to be canonicalize as the filter url.

    Eg.

    URL: home/category
    Canonical url: home/category

    URL:/home/category/page2
    Canonical url: home/category

    URL: /home/category/filter1-Filter2-Filter3
    Canonical url: /home/category/filter1-Filter2-Filter3

    URL: /home/category/filter1-Filter2-Filter3/page2
    Canonical url: /home/category/filter1-Filter2-Filter3

    Alberto
    Rank Math business

    Hello,

    Since I am not sure of the structure your URL are using (you said as an example this one: wyx .com/wooden-table/?color-red&&Type-Leather%%page2 but usually URLs don’t have the & added twice (nor the %) so maybe it was a mistake), I can give you a base code and you can customize it from there:

    /**
     * Allow changing of the canonical URL.
     *
     * @param string $canonical The canonical URL.
     */
    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
             // We use this since $canonical doesn't have the query string
             $queryString = $_SERVER['QUERY_STRING'];
             $url = $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?" . $queryString;
    
            // Now you should check if $queryString contains some parameters and if it does you would need to extract from there the pagination
            // For example, you could save it in a var like: $pagination
            // And return the new canonical like this: return $canonical . $pagination
    	return $canonical;
    });

    Looking forward to help you.

    Akshay
    Rank Math free

    Damn, This is little tough for me,

    Ok to make it simple, The link provide in the sensitive data.
    I want that link to be self canonicalized, This link is after added filters in the category page.

    Currently the current Canonical URL for above page is the category page. i.e. /restaurant-chairs/

    I want the filter page URL to be self canonicalize too. And Every paginated page after the filters applied, to be canonicalized again to the filter page url (The url mentioned in the sensitive data)

    Alberto
    Rank Math business

    Hello,

    I am trying to check it but after applying filters the URL I am getting is the one I shared in the Sensitive Data section and not one with && nor ?

    Is it a correct URL you want to canonicalize?

    Looking forward to help you.

    Akshay
    Rank Math free

    Yes the filters are correct, Ignore the garbage after ‘?’ its a plugin doing that
    so basically you applied filter, This creates a page. You can check the url (Sensitive Data)

    I want that generated url’s canonical url to be the generated URL only.
    Currently the canonical URL on the category “/restaurant-chairs/” is “/restaurant-chairs/”

    Any filter applied on “/restaurant-chairs/”, will generate a new URL (sensitive data), but the canonical url still currently remains the main category page url i.e “/restaurant-chairs/”,

    I am trying to make filtered result page’s canonical url to be the filtered page url itself!

    All I am trying to work on is, If the filter is applied, and we are getting a new URL, the Canonical URL to that filtered page should be the page url itself, and not “/restaurant-chairs/”

    • This reply was modified 4 years ago by Akshay.
    Alberto
    Rank Math business

    Hello,

    Could we log in your site to try the snippet there so it is easy to debug? To do that, please edit the first post on this ticket and include your WP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    Akshay
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Akshay
    Rank Math free

    I have given the required access!

    Akshay
    Rank Math free

    Hey support team, Any solution?

    Alberto
    Rank Math business

    Hello,

    I am sorry, I didn’t see the thread updated with your credentials. I am now trying to add the modifications but each time I try to save the modifications I am getting issues saving the functions.php file. Could you share some FTP credentials so I can modify the file from there?

    Looking forward to help you.

    Akshay
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Akshay
    Rank Math free

    Hello Alberto,
    It shouldn’t happen like this, But anyways, I have given the access. Do let me know what else is needed.

    Akshay
    Rank Math free

    Hey Guys, Any update on this? I really need your help!

    Hello,

    Sorry for not following up quickly.

    The only way to change the canonical URL of the dynamically generated paginated pages on your site is by using the following filter: https://rankmath.com/kb/filters-hooks-api-developer/#change-canonical-url

    You mentioned that you are using a Premerce filter for this. Do they offer any condition to check if the current page is a paginated page? Following is an example on how you can use this filter:

    `
    add_filter( ‘rank_math/frontend/canonical’, function( $canonical ) {
    if ( is_premmerce_filter_page() ) {
    return get_main_page_url();
    } // Please change the code in this condition.

    return $canonical;
    });
    `
    I am not familiar with the Premmerce plugin so sadly I cannot help you with the condition to use in this filter. Please contact the Premmerce team if you don’t know what condition to use to check for the paginated pages.

    I hope that helps. Please let us know if you need our help with anything else.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 15 replies - 1 through 15 (of 15 total)

The ticket ‘How to add self canonical url to facet pages?’ is closed to new replies.