Image Index SEO Issue with CDN
I have a similar issue with this case:
https://crunchify.com/maxcdn-and-wordpress-image-index-seo-issue-in-google-search-console-fix-cdn-image-links-and-avoid-duplicate-content-penalty/
The article shows how to fix it, but it only works for YOAST.
Can I do something like that with Rank Math? 😀
The case:
I’m using CDN with subdomain cdn.domain.com; they serve the images at cdn.domain.com/image.jpg
The problem is when I activated the Image URL in Rank Math Sitemap; the plugin serves URL as my root domain. Not the CDN URL.
Hope you guys understand what I’m saying
Hi Harun,
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.
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.