Title: WP_Speculation_Rules::has_rule
Published: April 28, 2025
Last modified: May 20, 2026

---

# WP_Speculation_Rules::has_rule( string $mode, string $id ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#changelog)

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

Checks whether a speculation rule for the given mode and ID already exists.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#parameters)󠁿

 `$mode`stringrequired

Speculative loading mode. Either `'prefetch'` or `'prerender'`.

`$id`stringrequired

Unique string identifier for the speculation rule.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?output_format=md#return)󠁿

 bool True if the rule already exists, false otherwise.

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

    ```php
    public function has_rule( string $mode, string $id ): bool {
    	return isset( $this->rules_by_mode[ $mode ][ $id ] );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-speculation-rules.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-speculation-rules.php#L224)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-speculation-rules.php#L224-L226)

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

| Used by | Description | 
| [WP_Speculation_Rules::add_rule()](https://developer.wordpress.org/reference/classes/wp_speculation_rules/add_rule/)`wp-includes/class-wp-speculation-rules.php` |

Adds a speculation rule to the speculation rules to consider.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_speculation_rules/has_rule/?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%2Fclasses%2Fwp_speculation_rules%2Fhas_rule%2F)
before being able to contribute a note or feedback.