How to check if current admin page is Gutenberg editor?

admin2025-06-05  2

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?

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?

Share Improve this question asked Dec 8, 2018 at 6:17 Marvin3Marvin3 6631 gold badge10 silver badges20 bronze badges 2
  • please try this code but i am not confirm – vikrant zilpe Commented Dec 8, 2018 at 7:35
  • global $current_screen; $current_screen = get_current_screen(); if ( ( method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor() ) || ( function_exists('is_gutenberg_page')) && is_gutenberg_page() ) ) { // DO SOMETHING } – vikrant zilpe Commented Dec 8, 2018 at 7:35
Add a comment  | 

1 Answer 1

Reset to default 3

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749116739a316504.html

最新回复(0)