Change canonical URL

#308861
  • Resolved Matthias
    Rank Math free

    Hello,

    I’m trying to change the canonical URL with the 'rank_math/frontend/canonical' filter, but it doesn’t seem to have any effect.

    I’m changing the og:url in the same way with the 'rank_math/opengraph/url' filter and there it works.

    Can you please help me?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello,

    Thank you for contacting us and sorry for any inconvenience that might have been caused due to that.

    Just by looking at the code, we can’t say for certain what exactly is happening because we are not aware of what those global variables are outputting when run on that filter.

    You can try to var_dump() each of those inside the canonical filter to see if they are outputting the desired result and make adjustments accordingly.

    Hope this helps solve your issues.

    ​​​​​​​Don’t hesitate to get in touch if you have any other questions.

    Hello,

    even if I just write

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	$canonical = "";
    	return $canonical;
    });

    or

    add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
    	return false;
    });

    it outputs the canonical.

    This filter doesn’t seem to have any effect at all.

    Prabhat
    Rank Math agency

    Hello,

    We tested on our end and the filter seems to be working as expected.

    Please hard-refresh the page after making changes to the filter and see if that works:
    Windows: CTRL + F5
    Mac: Command + Shift + R

    If not already, you can also try clearing your website and browser’s cache to test this.

    If the issue persists, please follow this troubleshooting guide to see if any plugin/theme is conflicting the restricting the filter from working: https://rankmath.com/kb/check-plugin-conflicts/

    Let us know how that goes.

    Thank you.

    Hi,

    I checked again and found out, that the filter is only working if called in functions.php but not if I call it before get_header() in the page template.

    But now I have the problem, that I need those global variables to set the new canonical URL.

    Any ideas?

    Thanks!

    Hello,

    Looking at your page now it seems that the canonical is already correct, so we assume you found a workaround to get those variables.

    Do you require any further assistance with this situation?

    Looking forward to hearing back from you.

    I resolved it with another way without the variables.

    Still it’s confusing to me, why some filter work in the page template while others don’t.

    Thanks!

    Hello,

    We’re glad that you have already found a workaround for this.

    Please feel free to reach out to us again in case you need any other assistance.

    We are here to help.

    Thank you.

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

The ticket ‘Change canonical URL’ is closed to new replies.