$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>How to check if current admin page is Gutenberg editor?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to check if current admin page is Gutenberg editor?

matteradmin9PV0评论
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.

Post a comment

comment list (0)

  1. No comments so far