Managed WordPress Help

CDN image indexing and Yoast SEO

Note: Before making any custom changes to your WordPress theme, you should add a child theme, to avoid losing your changes the next time you update the theme.

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.

  1. Connect to your site with File Manager or FTP.
  2. Go to the wp-content/themes directory.
  3. In the folder with your active theme, find and open the functions.php file.
  4. 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' );
        
  5. Save the changes.
  6. Sign in to WordPress.
  7. On the left-side menu, select Yoast SEO and then select Settings.
  8. Select Site features and scroll down to the APIs section.
  9. Find the XML sitemaps feature and disable it.
  10. 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

More Info

Share this article