移除 WordPress5.9.2前台的内联样式和Svg图像

您所在的位置:网站首页 前台的样式 移除 WordPress5.9.2前台的内联样式和Svg图像

移除 WordPress5.9.2前台的内联样式和Svg图像

2024-06-21 15:46| 来源: 网络整理| 查看: 265

最近将 WordPress 升级到了5.9.2,然后在查看源代码时发现 wordpress在头部插入了global-styles 内联样式,并向底部插入了很多的 svg 图像,对于国内主题的话,这个些代码显得有些多余了,因此决定把这些去掉。

移除头部的global-styles内联样式

在主题的functios.php添加

function remove_global_styles(){ wp_dequeue_style( 'global-styles' ); } add_action( 'wp_enqueue_scripts', 'remove_global_styles' ); 移除底部的svg图像

在使用主题的根目录下新建一个theme.json文件,写入下面代码

{ "version": 1, "settings": { "color": { "duotone": null } } } 一键移除内联样式和svg图像 function remove_global_styles(){ remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles'); remove_action('wp_footer', 'wp_enqueue_global_styles', 1); } add_action('after_setup_theme', 'remove_global_styles', 10, 0); 移除所有区块样式

在主题的functions.php中添加

function remove_wp_block_library_css(){ wp_dequeue_style( 'wp-block-library' ); wp_dequeue_style( 'wp-block-library-theme' ); wp_dequeue_style( 'wc-block-style' ); // 移除WOO插件区块样式 wp_dequeue_style( 'global-styles' ); // 移除 THEME.JSON } add_action( 'wp_enqueue_scripts', 'remove_wp_block_library_css', 100 ); }

欢迎关注我的公众号“xx主题网”,原创技术文章第一时间推送。

文章来源:https://www.xxzhuti.com/929.html



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3