Filter hook 'wp_speculation_rules_configuration'

in WP Core File wp-includes/speculative-loading.php at line 54

View Source

wp_speculation_rules_configuration

Filter Hook
Description
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. 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.

Hook Information

File Location wp-includes/speculative-loading.php View on GitHub
Hook Type Filter
Line Number 54

Hook Parameters

This hook doesn't accept any parameters.

Usage Examples

Basic Usage
<?php
// Hook into wp_speculation_rules_configuration
add_filter('wp_speculation_rules_configuration', 'my_custom_filter');

function my_custom_filter() {
    // Your custom filtering logic here
    return 'modified_value';
}

Source Code Context

wp-includes/speculative-loading.php:54 - How this hook is used in WordPress core
<?php
  49  	 *                                           default value for both of the keys is 'auto'. Other possible values
  50  	 *                                           for 'mode' are 'prefetch' and 'prerender'. Other possible values for
  51  	 *                                           'eagerness' are 'eager', 'moderate', and 'conservative'. The value
  52  	 *                                           `null` is used to disable speculative loading entirely.
  53  	 */
  54  	$config = apply_filters( 'wp_speculation_rules_configuration', $config );
  55  
  56  	// Allow the value `null` to indicate that speculative loading is disabled.
  57  	if ( null === $config ) {
  58  		return null;
  59  	}

PHP Documentation

<?php
/**
	 * 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.
	 *
	 * @since 6.8.0
	 * @see https://developer.chrome.com/docs/web-platform/prerender-pages
	 *
	 * @param 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.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 0
  • File: wp-includes/speculative-loading.php
Related Hooks

Related hooks will be displayed here in future updates.