wordpress如何屏蔽/移除内联样式

2025年01月23日 建站教程

wordpress模版中有许多没用的代码,比如头部内联样式 global-styles-inline-css和duotone svg等。那么我们如何屏蔽/去除这些内联代码呢?下面给大家简单介绍一下具体实现方法!

在当前主题的functions.php文件中新增以下代码:

//移除头部global-styles-inline-css
add_action('wp_enqueue_scripts', 'remove_global_styles_inline');
function remove_global_styles_inline(){
  wp_deregister_style( 'global-styles' );
  wp_dequeue_style( 'global-styles' );
}

//wp-block相关的冗余代码
add_action('wp_enqueue_scripts', 'remove_styles_inline');
function remove_styles_inline(){
  wp_deregister_style( 'global-styles' );
  wp_dequeue_style( 'global-styles' );
  wp_dequeue_style( 'wp-block-library' );
  wp_dequeue_style( 'wp-block-library-theme' );
  wp_dequeue_style( 'wc-block-style' );
}

本文链接:http://so.lmcjl.com/news/21907/

展开阅读全文
相关内容