删除古腾堡CSS

删除古腾堡CSS,css,wordpress,wordpress-gutenberg,Css,Wordpress,Wordpress Gutenberg,我已经在WordPress v4.9.8中安装了Gutenberg插件,并且正在尝试删除它附带的CSS,以便我可以提供自己的插件 这是包含的工作表: <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' /> 以及它的变

我已经在WordPress v4.9.8中安装了Gutenberg插件,并且正在尝试删除它附带的CSS,以便我可以提供自己的插件

这是包含的工作表:

<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' />

以及它的变体,但该文件仍然存在。我怎样才能删除它?

我添加这个比我的评论更完整的答案:

在尝试将脚本出列时,需要删除
-css
。它添加到HTML标记中,而不是css文件的实际标记

如果您搜索代码(随着Gutenberg进入core,队列的位置可能会改变),您可以找到:

wp_enqueue_style( 'wp-block-library' );
如您所见,没有
-css
。此解决方案可能适用于其他插件,人们在退出时遇到困难

编辑: 由于这仍然有一些吸引力,下面是处理它的代码:

add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
    wp_dequeue_style( 'wp-block-library' );
}

适合我。

最近发布了最新的古腾堡更新,很多人都想知道如何更新。正如下面的指南所示,您需要在添加操作中引用100

首先,您必须为
wp块库
创建一个保存
wp\u dequeue\u样式
的函数,然后这样调用它:

add_action( 'wp_enqueue_scripts', 'custom_function', 100 );

我正在使用此代码删除默认样式

//Disable gutenberg style in Front
function wps_deregister_styles() {
    wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );

在functions.php文件上粘贴以下代码

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

如果这对您有帮助,请告诉我。

由于wp\u dequeue\u风格的方法无法禁用wp编辑器字体(wp编辑器字体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);

另请参见我使用Wordpress 5.1。尝试了最上等的答案,但它们对我不起作用,
'wp\u enqueue\u scripts'
而不是
'wp\u print\u style'
起作用

以下是我的整个WordPress 5.1解决方案,可以在不加载膨胀样式表的情况下摆脱Gutenberg:

// 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
}
编辑:

它也适用于WordPress 5.2,因为它处理WooCommerce和Storefront主题添加的样式表,我在新插件中做了以下设置之一:


这并不能真正回答问题,但我怀疑像我这样的其他人最终会试图解决这个问题所暗示但没有解决的问题:
如何删除内联(WP 5.5+)店面gutenberg阻止内联css,因此您可以使用编辑器,即使它在店面主题中使用白对白或黑对黑?

下面的内容就可以做到这一点。将其放入functions.php文件或插件中

function clean_storefront_gutenberg_block_editor_customizer_css( $string ) {
  // return empty so the editor doesn't suck
  return '';
}
add_filter( 'storefront_gutenberg_block_editor_customizer_css', 'clean_storefront_gutenberg_block_editor_customizer_css' );

这只是取消了生成的CSS,因此没有任何附加到后端编辑器。前端保持不变。

在2021年,我尝试了上述大多数方法的变化,但都失败了。看看WordPress代码,我相信原因是古腾堡风格不再排队。我发现删除它的唯一方法是在打印之前删除它

// This is what works for me.
add_action( 'wp_print_styles', 'wps_deregister_styles', 9999 );
    
function wps_deregister_styles()
    global $wp_styles;
    $wp_styles->remove('wp-block-library');
}

从前端加载中删除Gutenberg块库CSS

函数smartwp\u remove\u wp\u block\u library\u css()
{
wp_出列_样式(“wp-block-library”);
wp_dequeue_样式(“wp-block-library-theme”);
wp_dequeue_style('wc-block-style');//删除块CSS
}
添加操作('wp\u排队\u脚本','smartwp\u删除\u wp\u块\u库\u css',999);

这个问题并非离题,但您可能会在上找到更好的答案,可能已经存在。请改用
wp\u enqueue\u scripts
。尝试
add_操作('wp_enqueue_scripts','wps_deregister_styles',100)检查古腾堡是如何添加样式的。另请参见@TamilSelvanC谢谢,这不起作用。我已经尝试过这么多的变化,这不是我第一次遇到这样的问题。真是令人沮丧的WP方面@马特桑德斯尝试从标记中删除
-css
。因此,
wp块库
您的意思可能是:
add_操作('wp_enqueue_scripts','wp_deregister_style',200)但这将删除任何已注册的样式-可能不是您想要的!你能分享这个功能吗?最好的答案+1接受答案的作者只是将此复制到他的答案中。@T.Todua不,我没有。我从原始问题中复制了代码,因为这个问题和我的答案越来越受关注。对我有用!不知道为什么我没有先尝试其他答案,但这是简洁的,适用于5.2。
function clean_storefront_gutenberg_block_editor_customizer_css( $string ) {
  // return empty so the editor doesn't suck
  return '';
}
add_filter( 'storefront_gutenberg_block_editor_customizer_css', 'clean_storefront_gutenberg_block_editor_customizer_css' );
// This is what works for me.
add_action( 'wp_print_styles', 'wps_deregister_styles', 9999 );
    
function wps_deregister_styles()
    global $wp_styles;
    $wp_styles->remove('wp-block-library');
}