最近将 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 );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。