Last active
April 19, 2022 13:47
-
-
Save joshuafredrickson/043c8af09f2ff398521188da13d3891d to your computer and use it in GitHub Desktop.
Block Editor Cleanup for WordPress 5.9 and Classic Editor (mu-plugin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Block Editor Cleanup | |
* Plugin URI: https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1025520487 | |
* Version: 1.0.1 | |
* Description: Remove WP 5.9 default block editor styles when using Classic Editor | |
* Author: joshuafredrickson | |
* Author URI: https://joshuafredrickson.com | |
* License: GNU General Public License v2 | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
add_action('after_setup_theme', function () { | |
if (! function_exists('is_plugin_active')) { | |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
} | |
// Return early if Classic Editor isn't enabled | |
if (! is_plugin_active('classic-editor/classic-editor.php')) { | |
return; | |
} | |
// Remove SVG and global styles | |
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles'); | |
// @link https://github.com/WordPress/gutenberg/issues/38299#issuecomment-1049011521 | |
remove_action('wp_body_open', 'wp_global_styles_render_svg_filters'); | |
// Remove wp_footer actions which add global inline styles | |
remove_action('wp_footer', 'wp_enqueue_global_styles', 1); | |
// Remove render_block filters which add unnecessary stuff | |
remove_filter('render_block', 'wp_render_duotone_support'); | |
remove_filter('render_block', 'wp_restore_group_inner_container'); | |
remove_filter('render_block', 'wp_render_layout_support_flag'); | |
}); | |
add_action('wp_enqueue_scripts', function () { | |
if (! function_exists('is_plugin_active')) { | |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
} | |
if (is_plugin_active('classic-editor/classic-editor.php')) { | |
// Dequeue block library styles | |
wp_dequeue_style('wp-block-library'); | |
} | |
}, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you and updated!