Make WordPress prerender pages as visitors hover over links for near-instant navigation, or turn speculative loading off.
add_filter( 'wp_speculation_rules_configuration', function ( ?array $config ): ?array {
// Prerender the next page when a visitor hovers over a link.
return [
'mode' => 'prerender', // 'prefetch' only downloads the HTML; 'prerender' fully loads the page.
'eagerness' => 'moderate', // 'conservative' waits for a click; 'moderate' starts on hover.
];
// To turn speculative loading off completely, return null instead:
// return null;
} );
Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.
Since WordPress 6.8, sites add speculation rules that let supporting browsers start loading the next page before the visitor clicks. The default is cautious: it only prefetches the page when the link is pressed. This snippet lets you choose a faster setting, or turn it off.
The wp_speculation_rules_configuration filter returns the mode and eagerness WordPress uses to build its speculation rules. prerender loads and renders the whole page in the background, so it appears instantly when clicked. moderate starts when the pointer rests on a link for a moment.
WordPress automatically excludes wp-admin, login links and URLs with query strings, which are more likely to change something.
wp_speculation_rules_href_exclude_paths filter.View your page source and find the <script type="speculationrules"> tag near the bottom. It should list prerender with moderate eagerness.