最近发现wordpress5.9+版本会在前台头部插入了global-styles 内联样式,并向底部插入了很多的 svg 图像,对于我们来说这个些代码显得有些多余了,因此决定把这些去掉。
在主题的functios.php添加
1 |
function mbt_remove_global_styles(){ wp_dequeue_style( 'global-styles' ); } add_action( 'wp_enqueue_scripts', 'mbt_remove_global_styles' ); |
那么,如何移除svg图像呢?在使用主题的根目录下新建一个theme.json文件,写入下面代码
1 |
{ "version": 1, "settings": { "color": { "duotone": null } } } |
一键移除内联样式和svg图像
1 |
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); |
移除所有区块样式
1 |
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 ); } |
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。