【问题标题】:Do i need to remove this wp-block-library-css (Gutenberg CSS)?我需要删除这个 wp-block-library-css (Gutenberg CSS) 吗?
【发布时间】:2021-10-21 21:59:31
【问题描述】:

我只是想要一些关于 WordPress 中这个标签的说明和建议。

即使我没有使用 Gutenberg,这个标签也会显示在我的 WordPress 头脑中。

link rel="stylesheet" id="wp-block-library-css"

这是必要的还是必需的? 我需要删除它以提高页面速度吗?
去掉这个标签有影响吗?

请赐教。

谢谢

【问题讨论】:

    标签: html wordpress header wordpress-theming wordpress-gutenberg


    【解决方案1】:

    我用来在不使用 Gutenberg 的网站上删除此样式表。

    我认为除了删除这个样式表之外没有其他效果,你可以安全地做到这一点。

    更进一步,您可以仅删除某些帖子类型,例如

    function remove_wp_block_library_css() {
      if( !is_singular('post') ) {
        wp_dequeue_style( 'wp-block-library' );
      }
    }
    add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css' );
    

    【讨论】:

    • 嗨@Pof,小部件怎么样?它正在使用块编辑器?我们应该如何处理?
    • @CarlDaveTampoy 是的,小部件现在默认使用块编辑器;您可以通过以下方法之一恢复对经典小部件界面的访问 - developer.wordpress.org/block-editor/how-to-guides/widgets/… 您不需要将任何其他 CSS 出列。
    【解决方案2】:

    如果您根本不使用 Gutenberg,您可以像这样进一步卸载样式:

    // Unload 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
    }
    

    【讨论】:

    • 这行得通,谢谢。对我来说,仅wp_dequeue_style('wp-block-library'); 部分就有效地从前端删除了我想摆脱的 CSS 资源。后端不变,如我所愿。你能澄清/确认这只会修改前端吗?另外,为什么 Gutenberg CSS 仍然加载在前端?我如何知道我的帖子是否使用了这些样式?
    猜你喜欢
    • 1970-01-01
    • 2020-08-29
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多