Introduced in WordPress 6.5 and refined in 6.6+, the Core Interactivity API represents the most important architectural addition to modern WordPress frontend development. It provides a standardized, ultra-lightweight reactive framework for building dynamic micro-frontends—like live search filters, modal dialogs, and instant cart drawers—directly in native HTML directives without requiring a separate React, Vue, or Webpack build setup.
The Core Philosophy: Server-Rendered HTML + Client Hydration
Traditional Single Page Applications (SPAs) ship massive JavaScript bundles that parse the entire DOM on the client side. This causes poor Largest Contentful Paint (LCP) and high Interaction to Next Paint (INP) latency on mobile devices. The WordPress Interactivity API follows an “isomorphic island” approach:
- Zero Initial JS Delay: HTML is rendered natively on the server by PHP, ensuring 100/100 SEO indexability, perfect Open Graph scraping, and sub-millisecond initial paint.
- Declarative Directives: HTML elements declare dynamic behavior using standard
data-wp-*attributes (e.g.,data-wp-on--click,data-wp-bind--hidden,data-wp-context). - Shared Global State: A global reactive store (powered by Preact signals under the hood) manages synchronized state across disconnected blocks on the entire page.
- Standardized Namespace Architecture: Eliminates JavaScript naming collisions between different plugins and themes through distinct store namespaces.
Step-by-Step: Building an Instant Live Search Filter
Let’s build a fully functional, reactive live snippet search filter using pure Interactivity API directives. We will create both the server template and the client store.
1. The Server-Rendered HTML Block Template (render.php)
2. Registering the Reactive Client Store (view.js)
Next, define the reactive actions and derived computed state inside your block or theme’s script module:
3. Enqueuing Modern Script Modules in PHP
In WordPress 6.5+, script modules are registered with wp_register_script_module() and enqueued with wp_enqueue_script_module():
Key Advantages Over Heavy Frontend Frameworks
| Feature / Metric | WordPress Interactivity API | React / Vue Frontend Island |
|---|---|---|
| Runtime Bundle Size | ~10 KB (Shared Core Runtime) | 45 KB – 130 KB per island |
| Build Pipeline Required | None (Native Script Modules) | Vite, Webpack, or Babel |
| Block Theme Interoperability | 100% Native to Gutenberg & FSE | Requires custom iframe/bridge wrappers |
| Interaction to Next Paint (INP) | < 35ms (Instant Microtask) | 120ms – 250ms (Hydration lag) |
| SEO & SSR Hydration | Zero layout shift, 100% server-rendered | Subject to client hydration flashes |
Production Best Practices for Interactivity API
- Keep Context Localized: Use
data-wp-contextfor component-level ephemeral state (search inputs, modal visibility, open/closed accordion panels) and reserve globalstatefor cross-component shared state (active cart items, currency converters, theme dark mode switches). - Always Ensure Progressive Enhancement: Ensure forms and links have standard HTML fallbacks so users without JavaScript or on slow 3G connections can still submit search queries or navigate pages seamlessly.
- Leverage Directives Instead of Event Listeners: Avoid manual
addEventListenercalls in your client scripts. Let the Interactivity API runtime bind events declaratively throughdata-wp-on--*directives for optimal memory cleanup when blocks are unmounted.
Experience the speed of native FSE architecture in action with our TipWP Pro Theme, built from the ground up on modern WordPress standards.
