Skip to content

Instantly share code, notes, and snippets.

@jdevalk
Last active October 9, 2018 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdevalk/c06834fb4e8c9953a563 to your computer and use it in GitHub Desktop.
Save jdevalk/c06834fb4e8c9953a563 to your computer and use it in GitHub Desktop.
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