Hi Ashok,
Thanks for getting in touch with us.
Please use this filter in your themeās functions.php file to include your CDN URLs in the sitemap:
/**
* Filter to Add CDN Image URLs in the Sitemap
*
* @param string $src Image URL.
* @param object $post Post object.
*/
add_filter( 'rank_math/sitemap/xml_img_src', function( $src, $post ){
$src = str_replace( 'http://domain.com', 'https://cdn.domain.com', $src );
return $src;
}, 10, 2);
Do change the domain to your actual domain name.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
For including images in the sitemap, i have to enable this option or it is not necessary ?
http://prnt.sc/s1eal3
I am using kinsta cdn and they provide total different url than as you have suggeted like cdn.techjobsfair.com so which one i have to use..
please have look the following url.
http://prnt.sc/s1eedk
Hello,
That option is for attachment URLs (so it means, the pages generated by WordPress for each image and not the images themselves).
If you need those pages indexed you need to enable that option. In any other situation, you don’t really need that option enabled.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Hello,
About the question “I have to also set property in the google console for indexing cdn images or just adding your code enough ?“, it is optional and about Kinsta and their CDN, as the screenshot you shared said, it is optional and it is to get extra data about the CDN, it doesn’t affect Rank Math nor Google ranks.
About the code, it is almost fine, it should be like the one I added to sensitive data.
-
This reply was modified 4 years, 7 months ago by Alberto.
Ok one more question.
when we use CDN for images path then we have to deal with canonical header and other settings or Rank Math plugin will do all the things ?
Like Robot.txt file change, add link with rel=”canonical” in header etc..
For example : https://cdnify.com/blog/improve-seo-with-cdn/
Hi Ashok,
Your posts/pages don’t need any changes because the canonical tag is automatically added by Rank Math.
Image files don’t need a canonical tag because that is needed only on HTML/PHP pages (like WP posts/pages/categories/tags etc.).
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.