• Is it possible to modify the output of the xml image source url to reflect the actual cdn url?

    For example:

    Current img url output is: example.com/…/someimage.jpg

    CDN url is: cdn-name.com/…/someimage.jpg

    For instance, with the yoast xml sitemap you can do this with

    function wpseo_cdn_filter( $uri ) {
    	return str_replace( 'https://example.com', 'https://cdn-name.com', $uri );

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi there! Could you provide me with a link to your sitemap, along with a specific example of what you’d like to accomplish?

    If you want it to remain private, you can contact us using the form here:
    http://jetpack.com/contact-support/

    Please make sure to include a link to this thread in your message. Thanks!

    Thread Starter darrencss

    (@darrencss)

    I don’t have a sitemap at present since the image url issue needs to be resolved first. I want to switch the ‘local image url’ to the ‘actual cdn url’ which is a different domain. I don’t know how else to explain this, it isn’t a unique situation I can assure you.

    Maybe another way to do it is just to disable the image url function. Is this possible?

    Thanks

    • This reply was modified 9 years, 8 months ago by darrencss.
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ๐Ÿš€

    You could use the jetpack_sitemap_url to change the output of the sitemap, and selectively change the structure of some of the URLs there:
    https://developer.jetpack.com/hooks/jetpack_sitemap_url/

    If, on the other hand, you’d like to remove images from the sitemap altogether, you can use the jetpack_sitemap_ns filter to remove the image namespace:
    https://developer.jetpack.com/hooks/jetpack_sitemap_ns/

    However, I must warn you against the potential effects this change may have on your site’s SEO. Most CDNs do not allow search engines to index their images; instead, they include a canonical link in the image headers, redirecting search engines to the original, local image. This is often preferred, as most people would not want a CDN URL to be indexed.

    I hope this helps.

    Thread Starter darrencss

    (@darrencss)

    Thanks, that should work.

    I hear what you say about the seo but you can (in some cases) register your CDN url in webmaster tools and google will index all the images very efficiently. Since I already have thousands of images indexed this way I didn’t want to change this, hence my request.

    The wpseo_cdn_filter was introduced as an option for their own xml sitemap for this very reason.
    https://yoast.com/wordpress/plugins/seo/api/

    Thanks again

    • This reply was modified 9 years, 8 months ago by darrencss.
    Thread Starter darrencss

    (@darrencss)

    So looking at the first option it seems a bit complex to get exactly right. I think the best option for me is to simply not have the image url at all.

    Could you offer an example jetpack_sitemap_ns function to drop the image namespace entirely?

    Many thanks

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ๐Ÿš€

    I’m sorry, after some testing, jetpack_sitemap_ns might not be ideal here. Instead, you’ll need to use jetpack_print_sitemap:
    https://developer.jetpack.com/hooks/jetpack_print_sitemap/

    That filter will allow you to filter the whole XML output.

    Thread Starter darrencss

    (@darrencss)

    OK, thanks.
    There isn’t any documentation about this though so is it possible to just filter out the images with a simple function?

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ๐Ÿš€

    $tree returns the whole data tree, so you can remove or change anything in there before it’s outputted on the sitemap page.

    To get started, you can dump the whole output of the data tree of the page, and you’ll consequently see what you can modify.
    If you don’t feel comfortable creating that code snippet on your own, you can look for WordPress professionals that can help you here:
    http://jobs.wordpress.net/
    https://jetpack.pro/

    I hope this helps.

    Thread Starter darrencss

    (@darrencss)

    OK, thanks for your help.

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

The topic ‘XML Sitemap Image URL’ is closed to new replies.