PHPwordpressbeginner
Disable Gutenberg Block Editor
Disable the Gutenberg editor and use the Classic Editor instead
Faisal Yaqoob
January 9, 2025
#gutenberg#classic-editor#wordpress#admin
Code
php
1 // Method 1: Disable Gutenberg completely 2 add_filter('use_block_editor_for_post', '__return_false', 10); 3
4 // Method 2: Disable for specific post types only 5 function disable_gutenberg_for_post_types($can_edit, $post_type) { 6 $disabled_post_types = array('page', 'custom_post_type'); 7
8 if (in_array($post_type, $disabled_post_types)) { 9 return false; 10 } 11
12 return $can_edit; 13 } 14 add_filter('use_block_editor_for_post_type', 'disable_gutenberg_for_post_types', 10, 2); 15
16 // Method 3: Disable for users with specific roles 17 function disable_gutenberg_for_roles($can_edit, $post) { 18 $current_user = wp_get_current_user(); 19 $disabled_roles = array('contributor', 'author'); 20
21 if (array_intersect($disabled_roles, $current_user->roles)) { 22 return false; 23 } 24
25 return $can_edit; 26 } 27 add_filter('use_block_editor_for_post', 'disable_gutenberg_for_roles', 10, 2); 28
29 // Bonus: Remove Gutenberg CSS from frontend 30 function remove_gutenberg_css() { 31 wp_dequeue_style('wp-block-library'); 32 wp_dequeue_style('wp-block-library-theme'); 33 wp_dequeue_style('wc-block-style'); // WooCommerce blocks 34 wp_dequeue_style('global-styles'); // Theme.json 35 } 36 add_action('wp_enqueue_scripts', 'remove_gutenberg_css', 100);
Disable Gutenberg Block Editor
This snippet provides different methods to disable the Gutenberg block editor in WordPress and revert to the Classic Editor.
// Method 1: Disable Gutenberg completely
add_filter('use_block_editor_for_post', '__return_false', 10);
// Method 2: Disable for specific post types only
function disable_gutenberg_for_post_types($can_edit, $post_type) {
$disabled_post_types = array('page', 'custom_post_type');
if (in_array($post_type, $disabled_post_types)) {
return false;
}
return $can_edit;
}
add_filter('use_block_editor_for_post_type', 'disable_gutenberg_for_post_types', 10, 2);
// Method 3: Disable for users with specific roles
function disable_gutenberg_for_roles($can_edit, $post) {
$current_user = wp_get_current_user();
$disabled_roles = array('contributor', 'author');
if (array_intersect($disabled_roles, $current_user->roles)) {
return false;
}
return $can_edit;
}
add_filter('use_block_editor_for_post', 'disable_gutenberg_for_roles', 10, 2);
// Bonus: Remove Gutenberg CSS from frontend
function remove_gutenberg_css() {
wp_dequeue_style('wp-block-library');
wp_dequeue_style('wp-block-library-theme');
wp_dequeue_style('wc-block-style'); // WooCommerce blocks
wp_dequeue_style('global-styles'); // Theme.json
}
add_action('wp_enqueue_scripts', 'remove_gutenberg_css', 100);
When to Use This
- Legacy Sites: Sites that were built with Classic Editor and don't need block editor features
- Client Preference: Some clients prefer the simpler Classic Editor interface
- Custom Meta Boxes: When using extensive custom meta boxes that don't work well with Gutenberg
- Performance: Removing unused Gutenberg CSS can slightly improve page load times
Alternative
Instead of using code, you can install the official Classic Editor plugin which is maintained by WordPress core team.
Related Snippets
Add Custom Admin Column
Add custom columns to the WordPress admin posts list with sortable functionality
PHPwordpressintermediate
phpPreview
// Add the custom column header
function add_featured_image_column($columns) {
// Insert after title column
$new_columns = array();
...#admin#custom-column#wordpress+2
1/9/2025
View
Register Custom Post Type
Complete example of registering a custom post type with all common options
PHPwordpressintermediate
phpPreview
function register_portfolio_post_type() {
$labels = array(
'name' => _x('Portfolio Items', 'Post type general name', 'textdomain'),
'singular_name' => _x('Portfolio Item', 'Post type singular name', 'textdomain'),
...#custom-post-type#wordpress#development+1
1/9/2025
View
Remove WordPress Version Number
Remove WordPress version number from header and RSS feeds for better security
PHPwordpressbeginner
phpPreview
// Remove version from head
remove_action('wp_head', 'wp_generator');
// Remove version from RSS feeds
...#security#wordpress#wp-head+1
1/9/2025
View