Disable WP Speculative Loading

04/16/2025
Back to Gists
<?php
/**
 * Disable Speculative Loading in WordPress
 *
 * WordPress 6.5+ introduces speculative loading (like prerendering and prefetching)
 * to improve perceived performance by preloading likely navigation targets.
 * This filter disables the feature entirely, which can be helpful if:
 * - You're troubleshooting performance issues
 * - You use dynamic or cache-sensitive content
 * - You want full control over browser loading behavior
 *
 * To use: add this code to your theme's functions.php file or a custom plugin.
 */

add_filter(
    'wp_speculation_rules_configuration',
    function ( $config ) {
        // Returning null disables all speculative loading rules.
        return null;
    }
);