use_block_editor_for_post()
Checks whether the specified post supports editing via the block editor (Gutenberg).
The block editor depends on REST API, so if the parameter show_in_rest=false
is set when registering the post type, the function will return false.
Use use_block_editor_for_post_type() when you need to check for block editor support by post type, not for a specific post.
1 time — 0.0007281 sec (slow) | 50000 times — 0.34 sec (very fast) | PHP 8.1.27, WP 6.5.2
Hooks from the function
Returns
true|false
. The function will return true
, if the post is edited via the block editor, and false
otherwise.
Usage
use_block_editor_for_post( $post );
- $post(int|WP_Post) (required)
- ID or post object WP_Post.
Examples
#1 Example of function usage
Code snippet from the "Elementor Website Builder" plugin:
add_action( 'admin_print_scripts-edit.php', [ __CLASS__, 'add_new_button_to_gutenberg' ], 11 ); function add_new_button_to_gutenberg() { global $typenow; if ( ! User::is_current_user_can_edit_post_type( $typenow ) ) { return; } // Introduced in WP 5.0 if ( function_exists( 'use_block_editor_for_post' ) && ! use_block_editor_for_post( $typenow ) ) { return; } // Deprecated/removed in Gutenberg plugin v5.3.0 if ( function_exists( 'gutenberg_can_edit_post_type' ) && ! gutenberg_can_edit_post_type( $typenow ) ) { return; } ?> <script type="text/javascript"> document.addEventListener( 'DOMContentLoaded', function() { var dropdown = document.querySelector( '#split-page-title-action .dropdown' ); if ( ! dropdown ) { return; } var url = '<?php echo esc_url( Plugin::$instance->documents->get_create_new_post_url( $typenow ) ); ?>'; dropdown.insertAdjacentHTML( 'afterbegin', '<a href="' + url + '">Elementor</a>' ); } ); </script> <?php }
Changelog
Since 5.0.0 | Introduced. |
Since 6.1.0 | Moved to wp-includes from wp-admin. |