Previously I could use is_gutenberg_page()
, but this function seems to be gone after 5.0 release.
Any tips on how to check if current admin page is gutenberg editor?
This question already has answers here: check if Gutenberg is currently in use (9 answers) Closed 6 years ago.Previously I could use is_gutenberg_page()
, but this function seems to be gone after 5.0 release.
Any tips on how to check if current admin page is gutenberg editor?
In 5.0 new function was introduced (docs):
WP_Screen::is_block_editor( bool $set = null )
which sets or returns whether the block editor is loading on the current screen.
So you can do that check using this code:
global $current_screen;
$current_screen = get_current_screen();
if ( method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor() ) {
// DO SOMETHING
}
You can also add to this condition
|| ( function_exists('is_gutenberg_page')) && is_gutenberg_page() )
to be compatible with older versions.