Interactive blocks with the Interactivity API, no extra framework

WordPress's Interactivity API is built for light interactions inside blocks. A real example from server to client.

Hamid Aarab Senior WordPress and WooCommerce Backend Developer
Published
Reading time
1 min read

Hamid Aarab April 8, 2026 1 min read

تصویر پیکسلی یک دکمه و پاسخ تعاملی آن
Contents (3)

The Interactivity API has been in core since WordPress 6.5. It targets interactions such as toggles, filters and counters: the server renders the initial markup and JavaScript only manages state.

Markup in render.php

<div data-wp-interactive="hamidarab/faq" <?php echo wp_interactivity_data_wp_context( [ 'open' => false ] ); ?>>
  <button data-wp-on--click="actions.toggle" data-wp-bind--aria-expanded="context.open">
    <?php echo esc_html( $attributes['question'] ); ?>
  </button>
  <div data-wp-bind--hidden="!context.open"><?php echo wp_kses_post( $content ); ?></div>
</div>

Logic in view.js

import { store, getContext } from '@wordpress/interactivity';

store( 'hamidarab/faq', {
  actions: {
    toggle() {
      const context = getContext();
      context.open = ! context.open;
    },
  },
} );

Because the content is rendered on the server, it stays readable without JavaScript and is fine for SEO.

Where it doesn’t fit

For complex apps with routing and a large global state, a full framework still makes more sense. The Interactivity API is the right tool for focused interactions inside WordPress pages.

$ ./request_review

Facing the same problem in your own store?

Senior WordPress and WooCommerce backend engineering for complex production problems.

Request a Technical Assessment

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *