代码之家  ›  专栏  ›  技术社区  ›  Matt Saunders

删除Gutenberg CSS

  •  8
  • Matt Saunders  · 技术社区  · 7 年前

    我在WordPressv4.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' />

    我尝试了以下方法:

    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' );
    }
    

    以及这种变化,但文件仍然存在。我怎样才能取下它?

    8 回复  |  直到 7 年前
        1
  •  9
  •   disinfor    7 年前

    我将此添加为比我的评论更完整的答案:

    你需要移除 -css 当试图使脚本出列时。它被添加到HTML标记中,而不是CSS文件的实际标记中。

    如果搜索代码(当Gutenberg进入核心时,排队的位置可能会改变),您可以找到:

    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' );
    }
    
        2
  •  14
  •   Кирилл Меркушев    7 年前

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

    //Disable gutenberg style in Front
    function wps_deregister_styles() {
        wp_dequeue_style( 'wp-block-library' );
    }
    add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
    
        3
  •  2
  •   M.K.Dan    7 年前

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

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

    如果这对你有帮助的话。

        4
  •  0
  •   Alexander Taubenkorb    7 年前

    因为wp-dequeue-样式方法不适用于 禁用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);
    

    也看到 https://github.com/dimadin/disable-google-fonts/blob/master/disable-google-fonts.php

        5
  •  0
  •   Owais Alam    7 年前

    您必须将此代码放在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 );
    
        6
  •  0
  •   Ryszard Jędraszyk    7 年前

    我使用WordPress 5.1。我试过了大多数赞成的答案,但它们对我不起作用, 'wp_enqueue_scripts' 而不是 'wp_print_styles' 做这个把戏。

    下面是我的整个WordPress5.1解决方案,它可以在不加载Bloat样式表的情况下清除Gutenberg:

    // Disable Gutenberg editor.
    add_filter('use_block_editor_for_post_type', '__return_false', 10);
    // Don't load the stylesheet.
    add_action( 'wp_enqueue_scripts', 'remove_block_css', 100 );
    function remove_block_css() {
        wp_dequeue_style( 'wp-block-library' ); 
    }
    
        7
  •  -1
  •   Matheus Lacerda Fidan Bacaj    7 年前
    add_action('wp_enqueue_scripts', 'wps_deregister_styles', 200);
    

    为我工作。

        8
  •  -1
  •   WPZA    7 年前

    最近发布了最新的古登堡更新,很多人想知道如何 remove wp-block-library from WordPress . 如指南所示,下面需要您在添加操作中引用100。

    首先,必须创建一个函数来保存 wp_dequeue_style 对于 wp-block-library 然后这样称呼它:

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