admin管理员组

文章数量:1291452

I am working on removing the default Gutenberg block library stylesheet and replacing it with custom pared-down styles. I do not want the original stylesheet to load on either the front or back end, as it means I'd need to add unnecessary bulk to the custom styles in order to override styles in the default stylesheet.

I've successfully dequeued the styles from the front end using the standard in a wp_enqueue_scripts action:

function test_function(){
    wp_dequeue_style('wp-block-library');
}
add_action( 'wp_enqueue_scripts', 'test_function' );

However, this does not dequeue the styles from the block editor. I have tried dequeuing from an admin_init action as well, and that also does not remove the styles from the block editor.

Is it possible to dequeue this stylesheet from both the front-end and the admin block editor?

I am working on removing the default Gutenberg block library stylesheet and replacing it with custom pared-down styles. I do not want the original stylesheet to load on either the front or back end, as it means I'd need to add unnecessary bulk to the custom styles in order to override styles in the default stylesheet.

I've successfully dequeued the styles from the front end using the standard in a wp_enqueue_scripts action:

function test_function(){
    wp_dequeue_style('wp-block-library');
}
add_action( 'wp_enqueue_scripts', 'test_function' );

However, this does not dequeue the styles from the block editor. I have tried dequeuing from an admin_init action as well, and that also does not remove the styles from the block editor.

Is it possible to dequeue this stylesheet from both the front-end and the admin block editor?

Share Improve this question asked May 27, 2021 at 23:59 StudioAlStudioAl 4941 gold badge3 silver badges15 bronze badges 1
  • you're using the frontend specific enqueue scripts hook, you should use the admin area specific hook instead, though there's probably a better more official way to do this than dequeuing – Tom J Nowell Commented May 28, 2021 at 0:12
Add a comment  | 

1 Answer 1

Reset to default 3

Of course, five minutes after I post the question, I find a solution: Using

wp_deregister_style('wp-block-library')

(instead of wp_dequeue_style('wp-block-library')) works for the block editor. It worked in either an admin_init or an admin_enqueue_scripts action.

本文标签: wp enqueue scriptDequeue Gutenburg Block Library CSS (39wpblocklibrary39) in Admin