Currently Available: Need a skilled Software Developer for your next project?
Categories
WordPress

Debugging Custom Code Overrides in Yoast XML Sitemaps

When your WordPress site’s Yoast SEO sitemap does not match what you expect, the XML file alone cannot tell you whether custom code changed it. Yoast uses its own settings and inclusion rules to decide which URLs belong in the sitemap. Theme or plugin filters can change that output, and cached responses or static files can change what visitors receive. In WordPress, a filter is a callback function that takes a value, optionally modifies it, and returns it for another part of the code to use.

You can narrow down the cause by comparing the live sitemap index and the relevant child sitemap against the settings and rules for your installed Yoast version. After that, test the code and cache layers in a controlled environment. This shows whether Yoast excluded the URL on purpose or custom code overrode it, and it points you toward the source of the change.

Check what Yoast should output by default

The sitemap index lists child sitemap files, and each child file holds URLs for included content types, authors, and taxonomies. Check both the index and the relevant child sitemap for your missing or unexpected URL. Even if a URL does not appear in the index, it can still show up in a child sitemap. Yoast’s sitemap index guidance explains how the index and its child files relate.

Start by confirming that you have XML sitemaps enabled in Yoast settings. Next, check whether the affected content type or taxonomy is set to appear in search results, because Yoast ties that setting directly to sitemap inclusion. Menu labels can vary by plugin version, so follow the interface installed on your site. The Yoast sitemap settings cover both the feature toggle and content-type behavior.

Enabling a content type does not mean every item in it will appear. Yoast’s functional specification lists several automatic exclusions:

  • Private or password-protected content
  • Items with a noindex setting
  • Items with a manually set canonical URL that differs from the default
  • Non-public content types or taxonomies
  • Paginated archive pages

A public content type also needs eligible entries, or its sitemap will be empty. For a single post or page, open its Yoast Advanced settings to inspect the noindex and canonical values, and check its publication status and any redirects. For broader exclusions, check the content-type or taxonomy settings. Yoast’s exclusion guidance walks through these individual content settings.

The specification sets 1,000 as the default number of items per sitemap. When a content type has more items than that, Yoast creates numbered overflow sitemaps and can generate up to 50,000 extra sitemap files. That cap applies to the number of extra files, rather than the total number of URLs. You should also expect a sitemap response to carry an X-Robots-Tag: noindex, follow header. That header tells search engines not to index the sitemap document itself. It does not mean Yoast has noindexed your site’s pages. If your missing URL belongs in a News sitemap, check the separate 48-hour publication window for eligible articles.

Separate generated XML from what visitors receive

Before you search the codebase, compare the raw sitemap response with what your browser or monitoring tool displays. Record the exact URL, response body, HTTP status, headers, and request time. If your browser displays raw XML instead of a styled table, the sitemap is not broken on that basis alone, because search engines read the XML data directly. Yoast’s sitemap error guidance covers browser presentation and common reasons content goes missing.

A stale response is a different problem from Yoast generating the wrong list of URLs. Yoast disabled its own sitemap caching by default in version 9.0, so WordPress plugins, hosting platforms, servers, and CDNs are the usual places where sitemap responses get cached. Check the response headers and every cache layer on your site. Then clear those caches or exclude sitemap URLs from caching, and test again. Yoast’s update troubleshooting guidance recommends checking those layers and describes its manual refresh method: disable the sitemap feature, clear your caches, and enable it again. Skip old code snippets meant for Yoast’s internal sitemap cache, since those only apply to older plugin versions.

You should also check for a static sitemap file on the server and confirm how the server routes the request. Yoast’s blank sitemap troubleshooting advises inspecting the page source for XML data, and it notes that a static sitemap file or a conflict can interfere with the output. Compare the direct response before and after you clear caches. If the response body changes only after you clear caches, you were looking at a stale response.

Find and trace the filters changing your sitemap

Yoast documents several filters that change sitemap membership and content. For example, wpseo_exclude_from_sitemap_by_post_ids removes specific post IDs, while wpseo_sitemap_exclude_post_type excludes an entire post type. Other documented hooks affect taxonomies, authors, terms, entries per sitemap, or the post URLs Yoast outputs. The Yoast sitemap API and customization guidance list these extension points. Check each hook’s behavior against your installed Yoast release before you change any code, because live documentation may not match every version.

Search your parent and child themes, functions.php, must-use plugins, custom plugins, and other relevant plugin code for add_filter( and wpseo_ sitemap hooks. Include broader Yoast callbacks that could alter entries or URLs, even if the hook name does not immediately resemble your symptom. For each match, trace everything the callback does. Note its priority, how many arguments it accepts, its conditions, and every value it can return. WordPress runs callbacks in priority order, starting with the lowest number, and runs callbacks with the same priority in the order your code registered them. A later callback can overwrite what an earlier callback returned, and a callback that returns the wrong value can change the decision Yoast receives. WordPress explains this behavior in its add_filter() reference and Filters handbook.

A matching hook name does not prove causation. A callback might run only for a specific post type, taxonomy, request, or environment. You have much stronger evidence when you remove or bypass that callback, see the expected XML return, and then restore the callback to reproduce the discrepancy. Record both response bodies and your cache state during this test so you do not mistake a cache refresh for a code change.

Isolate the theme and plugins safely

Run conflict tests on a staging site or in a troubleshooting mode that leaves normal visitor traffic unaffected. Yoast’s conflict-testing instructions start with all plugins disabled and an unmodified default theme active. Enable Yoast SEO by itself first. Next, activate your preferred theme (testing the parent theme before the child theme), Yoast add-ons, and the remaining plugins one at a time. Retest the same sitemap URL after each step. Yoast also cautions that deactivating Yoast alone is not a valid conflict test.

When the discrepancy comes back, narrow it down to the smallest combination of code that reproduces it. If enabling your preferred theme brings the issue back, inspect its functions and included files for registered filters. If the issue still appears with only Yoast and the default theme active, custom theme or plugin code is much less likely to be the cause. A Yoast defect or an environment issue is still possible. Keep a record of your clean baseline and the first change that reproduces the issue so another maintainer can verify your result.

Do not edit production theme files while you diagnose the problem. Back up the site before making updates or code changes, and keep debug output off public pages. WordPress’s debugging documentation covers WP_DEBUG and WP_DEBUG_LOG for development diagnostics and warns that displaying errors on screen can expose internal messages in your site’s public output.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *