Hello,
Thank you for contacting Rank Math, and sorry for any inconvenience that might have been caused due to that.
You can set up canonical URLs for all the posts of the custom post type by navigating to :
WordPress Dashboard > Posts > Edit Posts > Advanced Tab of Rank Math > Canonical URL
Once there, you can change the Canonical URL field to point to the main source of your content.
Here is a detailed article from our Knowledge Base on canonical URLs :
https://rankmath.com/kb/how-to-change-canonical-url/
You could also have a look at this link for more information:
https://rankmath.com/kb/advanced-tab/#canonical-url
We hope this information helps. Please don’t hesitate to get in touch with us, if you need help with anything else.
Thank you.
Hello there…
I am aware of that method. But he have more than 3000+ links. So editing them manually gonna take very long time.
Is there any other method via functions.php or any other.. He wants canonical only for one custom post type.
Hello,
If you want to add any custom canonical URL then you have to do it manually which is already mentioned by my colleague here.
Please note that Rank Math automatically generates the canonical URL for all your pages if they are set to index. The main purpose of adding a custom canonical to your pages in Rank Math is to let Google know that it is a duplicate page, and not to be indexed.
Hope this helps. Looking forward to helping you.
Thank you.
Yes buddy i understood the point but.. On some support tickets your colleagues have given a way to add canonical by post id’s or by category.. In my situation i want to add it to custom post type.
Is there a way?
Hello,
Please add this filter to your theme’s functions.php:
add_filter( 'rank_math/frontend/canonical', function( $canonical ) {
if (is_singular('bgmringtones')) {
$canonical = 'https://rankmath.com'; // This is the canonical that is going to be applied to all CPTs with this name
}
return $canonical;
});
Please note that it is going to be canonical for the entries under that CPT. You can add your URL instead of https://rankmath.com
.
Here is a guide on how you can add a filter:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Hope this helps. Please don’t hesitate to get in touch with us, if you need help with anything else.
Thank you.
Hello,
Glad that helped.
If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
Thank you.