删除古腾堡 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52277629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove Gutenberg CSS
提问by Matt Saunders
I have Gutenberg plugin installed in WordPress v4.9.8 and am trying to remove the CSS that comes with it so I can supply my own.
我在 WordPress v4.9.8 中安装了 Gutenberg 插件,我正在尝试删除它附带的 CSS,以便我可以提供自己的 CSS。
This is the sheet that gets included:
这是包含的工作表:
<link rel='stylesheet' id='wp-block-library-css' href='/wp-content/plugins/gutenberg/build/block-library/style.css?ver=1535795173' type='text/css' media='all' />
I have tried the following:
我尝试了以下方法:
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library-css' );
wp_deregister_style( 'wp-block-library-css' );
}
As well as variations of this, but the file persists. How can I remove it?
以及它的变体,但文件仍然存在。我怎样才能删除它?
回答by disinfor
I'm adding this as a more complete answer than my comment:
我将其添加为比我的评论更完整的答案:
You need to remove the -css
when trying to dequeue the script. That's added to the HTML markup and not the actual tag for the css file.
-css
尝试使脚本出列时,您需要删除。这被添加到 HTML 标记中,而不是 css 文件的实际标记。
If you search the code (the location of the enqueue may change as Gutenberg gets rolled into core), you can find:
如果您搜索代码(随着 Gutenberg 进入核心,入队的位置可能会发生变化),您可以找到:
wp_enqueue_style( 'wp-block-library' );
As you can see, there is no -css
. This solution may work for other plugins that people have trouble dequeuing styles.
如您所见,没有-css
. 此解决方案可能适用于人们无法出列样式的其他插件。
Edit:Since this still gets some traction, here is the code to handle it:
编辑:由于这仍然有一些吸引力,这里是处理它的代码:
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
回答by Кирилл Меркушев
I am use this code to to remove default style.
我使用此代码删除默认样式。
//Disable gutenberg style in Front
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
回答by Ryszard J?draszyk
I use Wordpress 5.1. Tried the most upvoted answers and they didn't work for me, 'wp_enqueue_scripts'
instead of 'wp_print_styles'
does the trick.
我使用 Wordpress 5.1。尝试了最受好评的答案,但它们对我不起作用,'wp_enqueue_scripts'
而不是'wp_print_styles'
诀窍。
Here is my whole WordPress 5.1 solution to get rid of Gutenberg without bloat stylesheets loading:
这是我的整个 WordPress 5.1 解决方案,可以在不加载臃肿样式表的情况下摆脱古腾堡:
// Disable Gutenberg editor.
add_filter('use_block_editor_for_post_type', '__return_false', 10);
// Don't load Gutenberg-related stylesheets.
add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
function remove_block_css() {
wp_dequeue_style( 'wp-block-library' ); // Wordpress core
wp_dequeue_style( 'wp-block-library-theme' ); // Wordpress core
wp_dequeue_style( 'wc-block-style' ); // WooCommerce
wp_dequeue_style( 'storefront-gutenberg-blocks' ); // Storefront theme
}
Edit:
编辑:
It works with WordPress 5.2 as well and because it handles the stylesheets added by WooCommerce and Storefront theme, I made this one of the settings in my new plugin:
它也适用于 WordPress 5.2,并且因为它处理 WooCommerce 和 Storefront 主题添加的样式表,所以我在我的新插件中将其作为设置之一:
https://wordpress.org/plugins/extra-settings-for-woocommerce/
https://wordpress.org/plugins/extra-settings-for-woocommerce/
回答by M.K.Dan
Paste the following code on your functions.php file
将以下代码粘贴到您的 functions.php 文件中
function custom_theme_assets() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'custom_theme_assets', 100 );
Please like if this has helped you.
如果这对您有帮助,请点赞。
回答by Alexander Taubenkorb
As the wp_dequeue_style-approach did not work to disable wp-editor-font (wp-editor-font-css)I used the following code:
由于 wp_dequeue_style-approach 无法禁用 wp-editor-font (wp-editor-font-css),我使用了以下代码:
function my_remove_gutenberg_styles($translation, $text, $context, $domain)
{
if($context != 'Google Font Name and Variants' || $text != 'Noto Serif:400,400i,700,700i') {
return $translation;
}
return 'off';
}
add_filter( 'gettext_with_context', 'my_remove_gutenberg_styles',10, 4);
Also see https://github.com/dimadin/disable-google-fonts/blob/master/disable-google-fonts.php
另见https://github.com/dimadin/disable-google-fonts/blob/master/disable-google-fonts.php
回答by Owais Alam
You will have to place this code inside of your functions.php which is typically located in your theme's folder.
您必须将此代码放在您的functions.php 中,该文件通常位于您的主题文件夹中。
function wp_dequeue_gutenberg_styles() {
wp_dequeue_style( ‘wp-block-library' );
wp_dequeue_style( ‘wp-block-library-theme' );
}
add_action( ‘wp_print_styles', ‘wp_dequeue_gutenberg_styles', 100 );
回答by user1173218
add_action('wp_enqueue_scripts', 'wps_deregister_styles', 200);
Works for me.
为我工作。
回答by WPZA
As the latest Gutenberg update has been released recently, a lot of people are wondering how to remove wp-block-library from WordPress. As the guide shows, below you need you to reference the 100 in your add_action.
由于最近发布了最新的 Gutenberg 更新,很多人想知道如何从 WordPress 中删除 wp-block-library。如指南所示,您需要在下面引用 add_action 中的 100。
Firslty, you must create a function that holds your wp_dequeue_style
for wp-block-library
and then call it as such:
首先,您必须创建一个保存您的wp_dequeue_style
for的函数,wp-block-library
然后这样调用它:
add_action( 'wp_enqueue_scripts', 'custom_function', 100 );