Back to Community

Fixing the 'discard_content' JavaScript Error in XML Sitemap Generator for Google

15 threads Sep 7, 2025 PluginXml sitemap generator for google

Content

Users of the 'XML Sitemap Generator for Google' plugin have reported a recurring JavaScript error in their WordPress admin area. This error can cause other custom scripts to malfunction and creates a poor user experience. This guide explains the cause and provides the steps to resolve it.

Understanding the Error

The error message in the browser's console typically appears as:

Uncaught TypeError: Cannot read properties of null (reading 'classList')
Uncaught TypeError: document.getElementById(...) is null

This error occurs because the plugin's JavaScript code is trying to manipulate an HTML element with the ID discard_content. However, recent updates to WordPress or WooCommerce have removed this element from the page. When the code runs, it cannot find the element, resulting in a null error that stops script execution.

Why This Happens

The error originates from code related to the plugin's beta program notification system. The JavaScript is designed to add or remove CSS classes from the notification's dismiss button (discard_content). If this element does not exist on the page—which can happen after core WordPress updates or on certain admin screens—the script fails.

How to Fix the 'discard_content' Error

Solution 1: Update the Plugin (Recommended)

The most straightforward solution is to ensure you are running the latest version of the plugin. The 'XML Sitemap Generator for Google' team has acknowledged this issue in their support threads and has stated that fixes for these JavaScript errors are included in subsequent updates. Always update your plugins to benefit from bug fixes and security patches.

  1. Navigate to your WordPress Dashboard.
  2. Go to Plugins → Installed Plugins.
  3. Find "XML Sitemap Generator for Google" in the list.
  4. If an update is available, you will see a link. Click Update Now.
  5. After updating, clear your browser cache and check if the console error is gone.

Solution 2: Apply a Temporary Code Fix (For Developers)

If you cannot update immediately or are experiencing the issue on a current version, a temporary workaround is to add a null check to the plugin's JavaScript code. This modification ensures the code only runs if the discard_content element exists.

Warning: This involves editing plugin files. Any changes you make will be overwritten the next time the plugin is updated. Always create a full backup of your site before proceeding.

  1. Access your website's files via FTP or your hosting provider's file manager.
  2. Navigate to the plugin directory: /wp-content/plugins/google-sitemap-generator/.
  3. You will need to locate the JavaScript file containing the problematic code. Based on error reports, it may be enqueued in a PHP file or within an inline script. Searching the codebase for "discard_content" can help you find it.
  4. Once located, find the offending lines of code. They will look similar to this:
    document.getElementById("discard_content").classList.add("discard_button_outside_settings");
        
  5. Modify the code to include a conditional check before execution:
    if (document.getElementById('discard_content')) {
        document.getElementById('discard_content').classList.add('discard_button_outside_settings');
    }
        
  6. Save the file and clear any caching mechanisms on your site (server, plugin, or browser cache).

Solution 3: Disable the Plugin

If the error is causing critical issues and other solutions are not viable, you can temporarily disable the "XML Sitemap Generator for Google" plugin. This will immediately stop the JavaScript error. Remember, this will also disable your XML sitemap functionality until the plugin is reactivated after an update.

Conclusion

The 'discard_content' null error is a known JavaScript conflict that arises from changes in the WordPress environment. The preferred solution is to update the plugin to its latest version. For those who need an immediate fix or are comfortable with code, adding a simple null check can resolve the conflict. As always, maintaining regular backups before making changes is crucial for site stability.

Related Support Threads Support