If you’re running Divi 5 with Rank Math SEO and your sitemap returns a 500 error, you’re not alone. The error looks like this in your PHP log:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted
in .../DynamicAssetsDetection.php on line 1164
Or sometimes:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted
in .../Style.php on line 491
Both point to the same root cause. Here’s what’s happening and how to fix it in three lines.
The Root Cause
Rank Math’s image parser renders your post content to find images for the sitemap. Specifically, class-image-parser.php does this for every post:
$content = do_blocks( $content );
That call triggers full Divi 5 block rendering for every post. On a site with many Divi-built pages, two of Divi’s static class properties accumulate data across all those render calls without ever resetting:
DynamicAssetsDetection::$detection_state->attribute_used— JSON-encodes every block’s attributes and concatenates them into one unbounded stringFrontEnd\Module\Style::$_styles— accumulates CSS declarations for every module rendered
With enough pages, both grow until memory is exhausted. 256 MB doesn’t cut it.
Divi does have its own sitemap guard (is_dynamic_front_end_request() checks get_query_var('sitemap')), but that only covers Divi’s own initialization pipeline — not the do_blocks() call coming from Rank Math independently.
The Fix
Rank Math provides a filter that fires just before do_blocks() is called. Return an empty string from it and the render never happens.
Add this to your child theme’s functions.php (or an included file):
$uri = strtok( $_SERVER['REQUEST_URI'] ?? '', '?' );
if (
isset( $_GET['sitemap'] )
|| isset( $_GET['xsl'] )
|| (bool) preg_match( '#(?:[^/]+-sitemap\d*|sitemap_index)\.xml$|[a-z-]*sitemap\.xsl$#i', $uri )
) {
add_filter( 'rank_math/sitemap/content_before_parse_html_images', '__return_empty_string', 1 );
}
That’s it.
Why the URL detection matters
You need to check both $_GET and REQUEST_URI because Rank Math registers WordPress rewrite rules that map pretty URLs like /page-sitemap.xml to index.php?sitemap=page server-side. That means $_GET is never populated for pretty sitemap URLs — only REQUEST_URI will have the original path.
The regex covers all three of Rank Math’s rewrite patterns:
/page-sitemap.xml,/post-sitemap2.xml— content sitemaps/sitemap_index.xml— the index/main-sitemap.xsl— the XSL stylesheet
What about images in the sitemap?
This filter only prevents Rank Math from extracting images from rendered block content. Featured images and media library attachments are collected through separate code paths and remain unaffected. If your images are already attached to posts or set as featured images, you won’t lose anything in the sitemap.
Why Not Just Increase the Memory Limit?
You could set memory_limit = 512M and it might work — until your site grows, and then it won’t. The real issue is unbounded accumulation across posts in a single request. More memory delays the problem; this fix eliminates it.
Performance Note
Rank Math caches generated sitemaps as static XML files in wp-content/uploads/rank-math/. Once cached, sitemap requests serve static XML directly and this filter never runs. The overhead only occurs on cache miss — the first generation or after a content change invalidates the cache.