skip to Main Content

I want to remove wp-reset-editor-styles because it inserts CSS properties like like revert, which goes against what I’m trying to accomplish (example below).

.editor-styles-wrapper p {
  font-size: revert;
  line-height: revert;
  margin: revert;
}

Here’s what I’ve attempted.

function remove_editor_resets() {
  wp_deregister_style('wp-reset-editor-styles');
}
add_action('admin_menu', 'remove_editor_resets');

It successfully removes the resets, but ends up breaking another style called wp-block-directory. Here’s what the relevant section of the load-styles.php URL looks like.

BEFORE: wp-block-directory

AFTER: wp-bloc&load%5Bchunk_1%5D=k-directory

I’ve attempted define( 'CONCATENATE_SCRIPTS', false ); but that does nothing.

I believe the issue has something to do with the way dependencies are setup in /wp-includes/script-loader.php.

2

Answers


  1. You were close. Try enqueue_block_editor_assets instead of admin_menu. Note that this will also remove some core styles needed by the editor.

    This seems to be a problem that a lot of people are having. Until WP releases an update around this, I think this is the best you can do (there may be additional styles needed):

    add_action('enqueue_block_editor_assets', function () {
        // Removes editor styles
        wp_deregister_style('wp-reset-editor-styles');
        // Add back key styles, there may be more
        // change the path as needed
        wp_enqueue_style('wp-block-editor-styles', '../../../wp/wp-includes/css/dist/block-editor/style.css', false);
        wp_enqueue_style('wp-edit-post-styles', '../../../wp/wp-includes/css/dist/edit-post/style.css', false);
    }, 102);
    

    Note: Tested on WP v5.8.3

    Login or Signup to reply.
  2. I had the same problem. All the "revert" porperties simply broke up my CSS on gutenberg preview.
    Here is the solution that I finally implemented on my website.

    • create an add_action on "enqueue_block_editor_assets".
    • Deregister "wp-reset-editor-styles"
    • Register a new stylesheet (with your custom CSS) and use as handle "wp-reset-editor-styles". You need to do this because wp-edit-blocks needs it as dependency.

    So now I have the following code :

    add_action( 'enqueue_block_editor_assets', 'my_enqueue_block_editor_assets', 102);
    function my_enqueue_block_editor_assets () {
        wp_deregister_style('wp-reset-editor-styles');
        wp_register_style( 'wp-reset-editor-styles', get_stylesheet_directory_uri() . '/stylesheets/my-custom-stylesheet.css', false, '1.0', 'all' );
    }
    

    Works perfectly on WP v5.9.3

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search