最近,发现WordPress 升级到5.9 版本,因为是深度优化版本,速度和其他代码确实好了不少。但是,在看网站源码时,却发现了会添加多余头部内联样式 global-styles-inline-css 和底部 duotone svg 图标的代码,这其实对于大部分主题来说并不需要或不太兼容。
所以,我们可以用以下代码对其进行移除:
移除顶部内联样式 global-styles-inline-css
将以下代码复制添加到你的当前 WordPress 主题的 functions.php 文件中:
//WordPress 移除头部 global-styles-inline-css add_action('wp_enqueue_scripts', 'zrg_remove_global_styles_inline'); function zrg_remove_global_styles_inline(){ wp_deregister_style( 'global-styles' ); wp_dequeue_style( 'global-styles' ); }
一般添加后即可移除了。
如果你还发现有 wp-block 其它相关的冗余代码,可以用下面的代码移除:
add_action('wp_enqueue_scripts', 'zrg_remove_styles_inline'); function zrg_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' ); }
移除底部 duotone svg 图标
在你的当前 WordPress 主题文件夹下添加一个 theme.json 文件,文件内容按下面的写上:
{ "version": 1, "setting": { "color": { "duotone": null } } }
这样就可以了。试试吧
点击数:247