• Dave

    (@csn123)


    My client has an issue whereby when ‘Alter HTML’ is enabled in the WebP Express plugin, it adds the following to the start of Yoast sitemap files:

    <!-- Alter HTML was skipped because the HTML is too big to process! (limit is set to 600000 bytes) -->

    This is causing Google to report on invalid XML, which it is thanks to that comment code. Is there a filter or block of code we can use to disable WebP Express on Yoast generated sitemap files, or simply remove the comment above from being echoed in the file which would resolve the issue?

Viewing 2 replies - 1 through 2 (of 2 total)
  • This code snippet fixed it for us. Add to your functions.php:

    
    // Hook into the wpseo_sitemap_index action
    add_action('wpseo_sitemap_index', 'custom_modify_sitemap_output');
    
    function custom_modify_sitemap_output() {
        // Start output buffering
        ob_start('custom_modify_sitemap_buffer');
    
        // Call the Yoast SEO sitemap index function
        do_action('wpseo_xml_sitemap_index', 'always', true);
    
        // End output buffering and get the modified sitemap content
        $modified_sitemap_content = ob_get_clean();
    
        // Log the original and modified sitemap content
        error_log('Original sitemap content: ' . ob_get_clean());
        error_log('Modified sitemap content: ' . $modified_sitemap_content);
    
        // Output the modified sitemap content
        echo $modified_sitemap_content;
    }
    
    function custom_modify_sitemap_buffer($buffer) {
        // Remove any whitespace before the XML declaration
        $buffer = preg_replace('/^\s+/', '', $buffer);
    
        // Ensure the XML declaration is at the beginning
        if (strpos($buffer, '<?xml') !== 0) {
            $buffer = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . $buffer;
        }
    
        return $buffer;
    }
    
    Thread Starter Dave

    (@csn123)

    I’ve applied the code but it makes no difference. I suspect this is because the sitemap_index.xml works fine but it’s the post-sitemap.xml that contains the comment code.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WebP Express Yoast SEO Bug’ is closed to new replies.