Replacing CDN Image URLs with Original URLs in Sitemap

#937906
  • Resolved illiminium
    Rank Math free

    Dear Rank Math Support Team,

    I hope this message finds you well.

    I am currently facing an issue where my Rank Math-generated sitemap includes Cloudflare CDN URLs for images instead of the original image URLs. I believe that having the original image URLs in the sitemap is a better practice for image SEO, as it improves the chances of my images being indexed and appearing in Google Search.

    To address this, I attempted to add the following code to my theme’s rank-math.php file to replace the CDN URLs with the original URLs in the sitemap:
    (I cannot submit code)

    An example of the issue:

    [moved to sensitive data section]

    Unfortunately, this code does not seem to resolve the issue, as the sitemap still includes the CDN URLs.

    Could you please advise on how to properly implement this replacement? If there’s a better approach or specific guidance for handling this within Rank Math, I’d greatly appreciate your support.

    Thank you for your time and assistance.

    Best regards,
    Thuy Nguyen

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

    Thank you for your query and we are so sorry about the trouble this must have caused.

    By default, Rank Math takes the original image path that is from the content and then you only need to apply that code if you need to replace the path with CDN.

    However, taking a look at your filter code, it seems that you’re using the wrong hook. Can you please try the code below and see if it works on your end?

    add_filter( 'rank_math/sitemap/xml_img_src', function( $src, $post ){
    	$src = str_replace( 'http://cdn.domain.com', 'https://domain.com', $src );
    	return $src;
    }, 10, 2);

    Replace the URL base accordingly.

    If the issue persists, please share some of the affected URLs associated to the image path you shared in the Sensitive data section of this tciket.

    Let us know how that goes. Looking forward to helping you.

    Hi Jeremy,
    Thank you for your reply. Unfortunately, none of the image URLs in my sitemap are being replaced with the original URLs; they all remain as the CDN URLs.
    Here’s the updated code I am using:
    https://pastebin.com/nm6f27fD
    Could this issue be related to Rank Math’s sitemap caching? If so, is there a way to clear or disable this cache to allow the changes to take effect?
    Thank you.
    Kind regards,
    Thuy

    Hello,

    It seems you are on the right track, but the issue could indeed be related to the caching of the sitemap.

    Please follow the steps below:

    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/

    We hope this helps. Please let us know if you have further questions or concerns.

    Thank you.

    Thank you! The issue got resolved when I followed the steps.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    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.

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

The ticket ‘Replacing CDN Image URLs with Original URLs in Sitemap’ is closed to new replies.