Skip to content

Docs: wrong use of wp_interactivity_state? #75827

Closed

Description

@eatse21

Hi, reading the docs on interactivity until this code example:

Isn't this should be instead replaced by wp_interactivity_data_wp_context to get a local context or moved out the div without echo to set global state?

Activity

  1. Mustafabharmal commented on Feb 24, 2026

    @Mustafabharmal
    Contributor

    The issue is in the getServerState() PHP example, it incorrectly uses echo wp_interactivity_state() inside a <div> tag as if it outputs HTML attributes (like wp_interactivity_data_wp_context() does), but wp_interactivity_state() sets global state and doesn't return HTML attributes. The fix is to call it without echo, outside the <div>, and add data-wp-interactive="myPlugin" to the element.
    Let me raise the PR with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions