Title: wp_print_speculation_rules
Published: February 24, 2026

---

# wp_print_speculation_rules()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Prints the speculation rules.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#description)󠁿

For browsers that do not support speculation rules yet, the `script[type="speculationrules"]`
tag will be ignored.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#source)󠁿

    ```php
    function wp_print_speculation_rules(): void {
    	$speculation_rules = wp_get_speculation_rules();
    	if ( null === $speculation_rules ) {
    		return;
    	}

    	wp_print_inline_script_tag(
    		(string) wp_json_encode(
    			$speculation_rules,
    			JSON_HEX_TAG | JSON_UNESCAPED_SLASHES
    		),
    		array( 'type' => 'speculationrules' )
    	);
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/speculative-loading.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/speculative-loading.php#L242)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/speculative-loading.php#L242-L255)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_speculation_rules()](https://developer.wordpress.org/reference/functions/wp_get_speculation_rules/)`wp-includes/speculative-loading.php` |

Returns the full speculation rules data based on the configuration.

  | 
| [wp_print_inline_script_tag()](https://developer.wordpress.org/reference/functions/wp_print_inline_script_tag/)`wp-includes/script-loader.php` |

Prints an inline script tag.

  | 
| [wp_json_encode()](https://developer.wordpress.org/reference/functions/wp_json_encode/)`wp-includes/functions.php` |

Encodes a variable into JSON, with some confidence checks.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_print_speculation_rules/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.8.0](https://developer.wordpress.org/reference/since/6.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_print_speculation_rules%2F)
before being able to contribute a note or feedback.