-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to detect "is-gutenberg" via PHP and JS #12200
Comments
For JS, I'm using: function isGutenbergActive() {
return typeof wp !== 'undefined' && typeof wp.blocks !== 'undefined';
} |
@elliotcondon I found some sample code that I think will help you with the PHP part of your question at https://wordpress.stackexchange.com/a/309955/10377. Can you have a look? |
@rilwis Good idea. Be sure to test with YoastSEO + Classic Editor. I ran into some issues where @designsimply Thanks. |
Ace! Closing as it looks like everything's covered now. |
@designsimply I was hoping to get an official response from the gutenberg developers as to how we should detect "is-gutenberg" in JS. By closing the ticket are you confirming the above solution is the official solution? |
No. It’s just a solution! Help requests can and should be answered by any contributor. I think to get an official response on something like this, you will want to submit what you’ve found as a documentation pull request to ask for a code review and that would be really cool because it will have the extra benefit of helping others in the community. Would you open a PR for this? |
@designsimply Thanks for the reply. I'm hesitant to open a PR regarding a question. Perhaps I am anticipating incorrectly, but I don't see this going down well. @noisysocks Quick question. If I as a plugin developer have a question about best practice or "how can I do this with PHP/JS?", where should I ask this question? Here on GitHub, or should I submit a PR containing an edited ".md" file with a question in it? |
I think that we're trying to move help requests out of GitHub to somewhere more suitable e.g. the WordPress support forums. In your case I'd probably plop quick questions into #core-editor on WP Slack. Regarding this question: I recommend detecting something more specific than "is Gutenberg loaded on the page?" because the line between Gutenberg and Core will become blurrier as we gradually use Gutenberg code on more and more WP Admin pages. For detecting if we're editing a post or page using the block editor, I would go with:
|
@noisysocks Thanks for the reply. IMO I'm not sure we should be asking these kinds of questions on slack. Having the question and answer available via google search (stackoverflow / github / etc) will help multiple developers who also have the same question. |
That's a very good point. |
@noisysocks That's why they pay me the big bucks 😉. |
Worth noting: In the meantime, you may consider checking for the presence of a defined |
…lsely detected as enabled when the Classic Editor Plugin is installed and Yoast SEO is installed. Yoast SEO enqueues the React library, which causes false positive on Gutenberg enabled. This false positive causes javascript errors when adding a page to a translation job or adding a page to an existing job. Using body class detection method defined WordPress/gutenberg#12200 (comment)
What is the easiest way to detect if the current edit screen is using Gutenberg in both PHP and JS.
For example, in PHP:
And in JS:
Thanks
Elliot
The text was updated successfully, but these errors were encountered: