Customize Preload sitemaps and priority

If you need to customize the way Preload works with sitemaps and their priority in the process, you can use the rocket_sitemap_preload_list and rocket_preload_order filters as shown below.

Heads up! This guide includes advanced configuration of the Preload feature. In most cases, the default behavior of this feature is the adequate, and customization is not required.

Tip: You can add the following code snippets as shown in this guide.

Preload only a custom sitemap

You can use the following snippet if you need to preload only a single custom sitemap and set Preload to ignore all the other compatible sitemaps.

function wprocket_preload_only_sitemap() {
    return ['https://domain.com/wp-content/files/custom-sitemap.xml'];
}
add_filter( 'rocket_sitemap_preload_list', 'wprocket_preload_only_sitemap', PHP_INT_MAX );

Preload only a group of sitemaps

In order to preload only the URLs found in multiple custom sitemaps, you can use the code below.

function wprocket_preload_only_sitemaps_multiple() {
    return ['https://domain.com/wp-content/files/custom-sitemap.xml', 'https://domain.com/wp-content/files/custom-sitemap-2.xml'];
}
add_filter( 'rocket_sitemap_preload_list', 'wprocket_preload_only_sitemaps_multiple', PHP_INT_MAX );

Preload additional custom sitemaps

Use the following snippet to ensure specific sitemaps are included in the preloading process, besides the compatible sitemaps.

function wprocket_preload_add_custom_sitemaps ( $sitemaps ){
    
    $sitemaps[] = 'https://domain.com/wp-content/files/custom-sitemap.xml';
    $sitemaps[] = 'https://domain.com/wp-content/files/custom-sitemap-2.xml';
    
    return $sitemaps;
}
add_filter( 'rocket_sitemap_preload_list', 'wprocket_preload_add_custom_sitemaps', PHP_INT_MAX );

Note: when using any of the above snippets, that include the rocket_sitemap_preload_list hook, Preload has to be disabled/re-enabled for the changes to be applied. 

Use-cases of preloading custom sitemaps

Below is the list of possible scenarios where you need to customize how the sitemaps Preload works:

  • You have a big ecommerce website, and need to limit the pages to be added to the preload queue.
  • Only the pages with critical content of your site need to be preloaded. You create a sitemap (with, for example all categories, landing pages and products) and use the first customization in the current article.
  • Some pages are not present in the compatible sitemaps. In this case, you can create a custom sitemap with those URLs, and add them using the third method.

Customize the priority of Preload

The  wp_wpr_rocket_cache table is used to track the progress of the Preload, each added URL has a unique id , which is an auto-increment value.

The  rocket_preload_order filter can be used to make the Preload run on URLs according to their id instead of their modified value.

Here's the snippet you should use:

add_filter( 'rocket_preload_order', function( $order ){
    return true;
}, 1);

Note: For the snippet to take effect, you'd need to go to Settings → Permalinks, and click on Save Changes, in your WordPress dashboard.

Use-case of customizing the priority of Preload

The default order of Preload is sufficient in most cases, but some pages can be preloaded first in case:

  • You have a big site and you need to make sure critical pages are always preloaded first.  So, you need to combine the usage of custom sitemaps with the priority option.

    When using custom sitemaps, they will be fetched first, their URLs will have the lowest  id , and therefore, those URLs will be prioritized in the preloading process.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.