Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet to replace image URIs with CDN image URIs in the XML sitemaps generated by WordPress SEO by Yoast. Obviously replace yoast.com with whatever is your site's domain.
<?php
/**
* Replace image URIs with CDN image URIs
*
* @param string $uri
*
* @return string
*/
function yst_cdn_filter( $uri ) {
if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
return $uri;
}
return str_replace( 'https://yoast.com', 'https://cdn.yoast.com', $uri );
}
add_filter( 'wpseo_xml_sitemap_img_src', 'yst_cdn_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment