Skip to content

How to detect "is-gutenberg" via PHP and JS #12200

Closed
@elliotcondon

Description

What is the easiest way to detect if the current edit screen is using Gutenberg in both PHP and JS.

For example, in PHP:

add_action('init', 'my_init');

function my_init() {
	
	// Detect if is Gutenberg.
	if( is_gutenberg_editor_active() ) {
		// Do something.
	} else {
		// Do something else.
	}
}

And in JS:

$(document).ready(function(){
	
	// Detect if is Gutenberg.
	if( wp.isGutenbergActive() ) {
		// Do something.
	} else {
		// Do something else.
	}
	 
 });

⚠️ Please keep all replies on topic. This should be a simple and straightforward question to answer without philosophical misdirection about "Classic vs Gutenberg" or "React vs PHP".

Thanks
Elliot

Metadata

Assignees

No one assigned

    Labels

    Needs Technical FeedbackNeeds testing from a developer perspective.[Type] Help RequestHelp with setup, implementation, or "How do I?" questions.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions