framecreative / wp-rocket-preload-sitemap
Limits preloading of WP Rocket cache pages to things in the sitemap - works off Yoast SEO sitemap by default.
Package info
github.com/framecreative/wp-rocket-preload-sitemap
Type:wordpress-plugin
pkg:composer/framecreative/wp-rocket-preload-sitemap
Requires
- php: >=8.1.0
- composer/installers: ^2.0
README
Restricts WP Rocket's preload feature to the URLs found in a single sitemap. Any URL not present in the sitemap is excluded from preloading — it will still be cached normally when a visitor hits it, it just won't be warmed in advance.
Based on WP Rocket's official helper plugin samples, adapted for Frame Creative sites.
Requirements
- PHP 8.1+
- WP Rocket (active, with preload enabled)
- Yoast SEO (optional — used for sitemap auto-detection)
Installation
Released on Packagist only, installed via Composer:
composer require framecreative/wp-rocket-preload-sitemap
The package type is wordpress-plugin, so composer/installers will place it in wp-content/plugins/. Activate it from the WordPress admin as usual.
How the sitemap URL is chosen
The sitemap URL is resolved lazily (when WP Rocket's preload actually runs, not at plugin load), so it doesn't depend on plugin load order. Resolution order:
WPR_HELPER_CUSTOM_SITEMAP_URLconstant — if pre-defined, wins over everything.FC_SITEMAP_URLconstant — define it inwp-config.phpto point at any sitemap:define( 'FC_SITEMAP_URL', 'https://example.com/custom-sitemap.xml' );
- Yoast SEO — if Yoast is active, its
sitemap_index.xmlURL is used automatically. - Fallback —
{home_url}/sitemap_index.xml.
How it works
- Filters
rocket_sitemap_preload_listso WP Rocket's preload crawler only reads the chosen sitemap. - Filters
rocket_preload_exclude_urlsso any URL not present in the sitemap is excluded from the preload table. - Attachment URLs are never preloaded, regardless of sitemap state. Detection covers
?attachment_id=permalinks, direct files under/wp-content/uploads/, and pretty attachment pages (matched by attachment slug lookup). - The parsed list of sitemap URLs is cached in the
rocket_custom_sitemap_linkstransient for 24 hours. Delete that transient to force a re-fetch after changing the sitemap. - If the sitemap can't be fetched (or comes back empty), nothing else is excluded — better to preload too much than to empty the preload table over a transient error. Failures are cached for 5 minutes so a broken sitemap doesn't trigger a fetch for every URL WP Rocket evaluates.
On activation
To make the sitemap change take effect immediately, activation will:
- Clear the cached sitemap URL list
- Truncate WP Rocket's preload table (
{prefix}wpr_rocket_cache), if it exists - Clear the WP Rocket cache for the domain
- Toggle the preload setting off and on to restart the preload
On deactivation
The cached sitemap URL list is cleared and the preload setting is toggled off and on again, so WP Rocket rebuilds its preload list without the sitemap restriction.
Both hooks only touch WP Rocket settings when WP Rocket is active, and never force-enable a preload that was switched off.
License
GPL-2.0-or-later