CDN image indexing and Yoast SEO
To ensure images are being indexed properly by Google Search Console when using the Yoast SEO plugin and a CDN, you should add a small snippet of code to the top of the functions.php file. This code will allow Yoast SEO to properly generate the sitemap for your WordPress website.
- Connect to your site with File Manager or FTP.
- Go to the wp-content/themes directory.
- In the folder with your active theme, find and open the functions.php file.
- In the functions.php file add this snippet of code to the top of the file and replace example.com with your own domain name.
function wpseo_cdn_filter($uri) { return str_replace('https://www.example.com', 'https://secureservercdn.net/example.com/', $uri); } add_filter( 'wpseo_xml_sitemap_img_src', 'wpseo_cdn_filter' );
- Save the changes.
- Sign in to WordPress.
- On the left-side menu, select Yoast SEO and then select Settings.
- Select Site features and scroll down to the APIs section.
- Find the XML sitemaps feature and disable it.
- Clear the cache and enable the sitemap feature again - that will force the sitemap to rebuild.
The sitemap will now use the CDN URL to reference the images. After this change it could take several days for the images to re-index in your Google Search Console.
Next steps
- Log in to the Google Search Console with your Google login.