Title: wp_interactivity
Published: April 3, 2024
Last modified: February 24, 2026

---

# wp_interactivity(): 󠀁[WP_Interactivity_API](https://developer.wordpress.org/reference/classes/wp_interactivity_api/)󠁿

## In this article

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

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

Retrieves the main [WP_Interactivity_API](https://developer.wordpress.org/reference/classes/wp_interactivity_api/)
instance.

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

It provides access to the [WP_Interactivity_API](https://developer.wordpress.org/reference/classes/wp_interactivity_api/)
instance, creating one if it doesn’t exist yet.

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

 [WP_Interactivity_API](https://developer.wordpress.org/reference/classes/wp_interactivity_api/)
The main [WP_Interactivity_API](https://developer.wordpress.org/reference/classes/wp_interactivity_api/)
instance.

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

    ```php
    function wp_interactivity(): WP_Interactivity_API {
    	global $wp_interactivity;
    	if ( ! ( $wp_interactivity instanceof WP_Interactivity_API ) ) {
    		$wp_interactivity = new WP_Interactivity_API();
    	}
    	return $wp_interactivity;
    }
    ```

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

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

| Used by | Description | 
| [wp_interactivity_get_context()](https://developer.wordpress.org/reference/functions/wp_interactivity_get_context/)`wp-includes/interactivity-api/interactivity-api.php` |

Gets the current Interactivity API context for a given namespace.

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

Returns an array representation of the current element being processed.

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

Registers all the default WordPress Script Modules.

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

Processes the interactivity directives contained within the HTML content and updates the markup accordingly.

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

Gets and/or sets the initial state of an Interactivity API store for a given namespace.

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

Gets and/or sets the configuration of the Interactivity API for a given store namespace.

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

Finds a script module ID for the selected block metadata field. It detects when a path to file was provided and optionally finds a corresponding asset file with details necessary to register the script module under with an automatically generated module ID. It returns unprocessed script module ID otherwise.

  |

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

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

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

## User Contributed Notes

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