Hello,
Thank you for contacting the support, and sorry for any inconvenience that might have been caused due to that.
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);
Change the domain to your actual domain.
More of that here: https://rankmath.com/kb/filters-hooks-api-developer/#sitemap-cdn-urls
Let me know if it works on your end. Looking forward to helping you.
I think this code is just for replacing the domain name on the sitemap
http://domain.com/wp-content/uploads/2021/07/image1.png
To
https://cdn.domain.com/wp-content/uploads/2021/07/image1.png
This does not work in my case because the sitemap has no CDN link.
I added the images to the CDN and updated the link on the WordPress page so that the link is not visible on my sitemap.
CDN link like that – “https://cdn.example.com/example/image1.jpg”,
Hello,
The filter I shared does change the domain, but not for the sitemap URL but for the image URLs. You may check the guide added in the comments. https://rankmath.com/kb/filters-hooks-api-developer/#sitemap-cdn-urls
Could you please confirm if you have tried implementing the filter? If not yet, please do so and follow the steps below to refresh the entire sitemap:
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/pipRDp
2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
https://rankmath.com/kb/exclude-sitemaps-from-caching/
Let us know how it goes. We are looking forward to helping 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.