wp_speculation_rules_configuration filter-hookWP 6.8.0

Filters the way that speculation rules are configured.

The Speculation Rules API is a web API that allows to automatically prefetch or prerender certain URLs on the page, which can lead to near-instant page load times. This is also referred to as speculative loading.

There are two aspects to the configuration:

  • The "mode" (whether to "prefetch" or "prerender" URLs).
  • The "eagerness" (whether to speculatively load URLs in an "eager", "moderate", or "conservative" way).

By default, the speculation rules configuration is decided by WordPress Core ("auto"). This filter can be used to force a certain configuration, which could for instance load URLs more or less eagerly.

For logged-in users or for sites that are not configured to use pretty permalinks, the default value is null, indicating that speculative loading is entirely disabled.

Usage

add_filter( 'wp_speculation_rules_configuration', 'wp_kama_speculation_rules_configuration_filter' );

/**
 * Function for `wp_speculation_rules_configuration` filter-hook.
 * 
 * @param array|null $config Associative array with 'mode' and 'eagerness' keys, or `null`. The default value for both of the keys is 'auto'. Other possible values for 'mode' are 'prefetch' and 'prerender'. Other possible values for 'eagerness' are 'eager', 'moderate', and 'conservative'. The value `null` is used to disable speculative loading entirely.
 *
 * @return array
$config(array<string,)
string>|null $config Associative array with 'mode' and 'eagerness' keys, or null. The default value for both of the keys is 'auto'. Other possible values for 'mode' are 'prefetch' and 'prerender'. Other possible values for 'eagerness' are 'eager', 'moderate', and 'conservative'. The value null is used to disable speculative loading entirely.

Changelog

Since 6.8.0 Introduced.

Where the hook is called

wp_speculation_rules_configuration
wp-includes/speculative-loading.php 54
$config = apply_filters( 'wp_speculation_rules_configuration', $config );

Where the hook is used in WordPress

Usage not found.