Replace WordPress SEO Image URIs in XML Sitemaps for CDN

As longtime fans of WordPress SEO, we wanted to share this great little snippet by Yoast. This snippet replaces image URIs to CDN URIs within your XML sitemap created by the WordPress SEO plugin. Before you add this to the functions.php of your WordPress theme, be sure to change the default URIs within the snippet from http://wpsnipp.com and http://cdn.wpsnipp.com to your own URIs.

function yst_cdn_filter( $uri ) {
	if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
		return $uri;
	return str_replace( 'http://wpsnipp.com', 'http://cdn.wpsnipp.com', $uri );
add_filter( 'wpseo_xml_sitemap_img_src', 'yst_cdn_filter' );

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!