How to detect the usage of Gutenberg
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
5
down vote
favorite
The new editor called Gutenberg is here as plugin in 4.9, and as core functionality called Block Editor, in 5.0. Regarding to it, it is often needed to determine programmatically which editor is used to edit post or page in the site console. How to do it?
gutenberg
add a comment |
up vote
5
down vote
favorite
The new editor called Gutenberg is here as plugin in 4.9, and as core functionality called Block Editor, in 5.0. Regarding to it, it is often needed to determine programmatically which editor is used to edit post or page in the site console. How to do it?
gutenberg
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
2
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.
– KAGG Design
Nov 30 at 11:23
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
The new editor called Gutenberg is here as plugin in 4.9, and as core functionality called Block Editor, in 5.0. Regarding to it, it is often needed to determine programmatically which editor is used to edit post or page in the site console. How to do it?
gutenberg
The new editor called Gutenberg is here as plugin in 4.9, and as core functionality called Block Editor, in 5.0. Regarding to it, it is often needed to determine programmatically which editor is used to edit post or page in the site console. How to do it?
gutenberg
gutenberg
edited Nov 30 at 11:02
Mark Kaplun
20.2k52754
20.2k52754
asked Nov 30 at 10:01
KAGG Design
1,209211
1,209211
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
2
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.
– KAGG Design
Nov 30 at 11:23
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25
add a comment |
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
2
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.
– KAGG Design
Nov 30 at 11:23
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
2
2
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,
the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.– KAGG Design
Nov 30 at 11:23
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,
the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.– KAGG Design
Nov 30 at 11:23
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25
add a comment |
2 Answers
2
active
oldest
votes
up vote
7
down vote
There are several variants:
- WordPress 4.9, Gutenberg plugin is not active
- WordPress 4.9, Gutenberg plugin is active
- WordPress 5.0, Block Editor by default
- WordPress 5.0, Classic Editor plugin is active
- WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected
All the mentioned variants can be processed by the following code:
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
// Block editor since 5.0.
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = get_option( 'classic-editor-replace' ) === 'no-replace';
return $use_block_editor;
}
Function returns true if block editor is active by any means, and false – in the case if classic editor is here. This function must only be used after plugins_loaded
action is fired.
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
add a comment |
up vote
1
down vote
You can use
add_action( 'enqueue_block_editor_assets', 'your_function_name' );
which is only fired when editing content with Gutenberg.
New contributor
This code works only on editor page.
– KAGG Design
yesterday
What aboutenqueue_block_assets
?
– Marc
14 hours ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
There are several variants:
- WordPress 4.9, Gutenberg plugin is not active
- WordPress 4.9, Gutenberg plugin is active
- WordPress 5.0, Block Editor by default
- WordPress 5.0, Classic Editor plugin is active
- WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected
All the mentioned variants can be processed by the following code:
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
// Block editor since 5.0.
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = get_option( 'classic-editor-replace' ) === 'no-replace';
return $use_block_editor;
}
Function returns true if block editor is active by any means, and false – in the case if classic editor is here. This function must only be used after plugins_loaded
action is fired.
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
add a comment |
up vote
7
down vote
There are several variants:
- WordPress 4.9, Gutenberg plugin is not active
- WordPress 4.9, Gutenberg plugin is active
- WordPress 5.0, Block Editor by default
- WordPress 5.0, Classic Editor plugin is active
- WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected
All the mentioned variants can be processed by the following code:
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
// Block editor since 5.0.
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = get_option( 'classic-editor-replace' ) === 'no-replace';
return $use_block_editor;
}
Function returns true if block editor is active by any means, and false – in the case if classic editor is here. This function must only be used after plugins_loaded
action is fired.
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
add a comment |
up vote
7
down vote
up vote
7
down vote
There are several variants:
- WordPress 4.9, Gutenberg plugin is not active
- WordPress 4.9, Gutenberg plugin is active
- WordPress 5.0, Block Editor by default
- WordPress 5.0, Classic Editor plugin is active
- WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected
All the mentioned variants can be processed by the following code:
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
// Block editor since 5.0.
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = get_option( 'classic-editor-replace' ) === 'no-replace';
return $use_block_editor;
}
Function returns true if block editor is active by any means, and false – in the case if classic editor is here. This function must only be used after plugins_loaded
action is fired.
There are several variants:
- WordPress 4.9, Gutenberg plugin is not active
- WordPress 4.9, Gutenberg plugin is active
- WordPress 5.0, Block Editor by default
- WordPress 5.0, Classic Editor plugin is active
- WordPress 5.0, Classic Editor plugin is active, but in site console in “Settings > Writing” the option “Use the Block editor by default…” is selected
All the mentioned variants can be processed by the following code:
/**
* Check if Block Editor is active.
* Must only be used after plugins_loaded action is fired.
*
* @return bool
*/
function is_active() {
// Gutenberg plugin is installed and activated.
$gutenberg = ! ( false === has_filter( 'replace_editor', 'gutenberg_init' ) );
// Block editor since 5.0.
$block_editor = version_compare( $GLOBALS['wp_version'], '5.0-beta', '>' );
if ( ! $gutenberg && ! $block_editor ) {
return false;
}
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once ABSPATH . 'wp-admin/includes/plugin.php';
}
if ( ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) {
return true;
}
$use_block_editor = get_option( 'classic-editor-replace' ) === 'no-replace';
return $use_block_editor;
}
Function returns true if block editor is active by any means, and false – in the case if classic editor is here. This function must only be used after plugins_loaded
action is fired.
edited Nov 30 at 14:30
kero
3,02511024
3,02511024
answered Nov 30 at 10:01
KAGG Design
1,209211
1,209211
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
add a comment |
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
not going o downvote, but it is not a fail safe answer. You should do detection based on actions or filters being triggered, not based n the existence of a file or a function. There are several ways to disable gutenberg and the classic editor is only one of them.
– Mark Kaplun
Nov 30 at 16:02
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
or to say it differently, you should never even try to detect if gutenberg is used or not, but instead just hook whatever functionality you need on the relevant gutenberg hooks in addition to hooking on the tinymce hooks
– Mark Kaplun
Nov 30 at 16:05
add a comment |
up vote
1
down vote
You can use
add_action( 'enqueue_block_editor_assets', 'your_function_name' );
which is only fired when editing content with Gutenberg.
New contributor
This code works only on editor page.
– KAGG Design
yesterday
What aboutenqueue_block_assets
?
– Marc
14 hours ago
add a comment |
up vote
1
down vote
You can use
add_action( 'enqueue_block_editor_assets', 'your_function_name' );
which is only fired when editing content with Gutenberg.
New contributor
This code works only on editor page.
– KAGG Design
yesterday
What aboutenqueue_block_assets
?
– Marc
14 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
You can use
add_action( 'enqueue_block_editor_assets', 'your_function_name' );
which is only fired when editing content with Gutenberg.
New contributor
You can use
add_action( 'enqueue_block_editor_assets', 'your_function_name' );
which is only fired when editing content with Gutenberg.
New contributor
New contributor
answered Nov 30 at 16:27
Marc
111
111
New contributor
New contributor
This code works only on editor page.
– KAGG Design
yesterday
What aboutenqueue_block_assets
?
– Marc
14 hours ago
add a comment |
This code works only on editor page.
– KAGG Design
yesterday
What aboutenqueue_block_assets
?
– Marc
14 hours ago
This code works only on editor page.
– KAGG Design
yesterday
This code works only on editor page.
– KAGG Design
yesterday
What about
enqueue_block_assets
?– Marc
14 hours ago
What about
enqueue_block_assets
?– Marc
14 hours ago
add a comment |
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f320653%2fhow-to-detect-the-usage-of-gutenberg%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
add_action( 'admin_enqueue_scripts', 'wpse_gutenberg_editor_test' ); function wpse_gutenberg_editor_test() { if( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { // your gutenberg editor related CODE here } else { // this is not gutenberg. // this may not even be any editor, you need to check the screen. } }
– vikrant zilpe
Nov 30 at 11:06
please check this :artiss.blog/2018/09/detecting-per-post-use-of-gutenberg
– vikrant zilpe
Nov 30 at 11:08
and this davidsword.ca/development/…
– vikrant zilpe
Nov 30 at 11:09
2
@vikrantzilpe please do not rely to an outdated information. It is better to test what you are writing. For example,
the_gutenberg_project()
function exists only in Gutenberg plugin, but not in the WP 5.0 Core.– KAGG Design
Nov 30 at 11:23
ok thanks inform me
– vikrant zilpe
Nov 30 at 11:25