WooCommerce通过以下CSS文件设置图标样式:woocommerce/assets/css/menu.css
, 这是相应的代码(打印得很好,或者实际上,我是从woocommerce/assets/css/menu.scss
):
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
font-family: \'WooCommerce\' !important;
content: \'\\e03d\';
}
因此您可以更改
font-family
以及
content
(和其他)属性以适合您的自定义图标。
下面是通过将图标更改为使用background-image
:
// We hook to the `admin_enqueue_scripts` action with a priority of `11`, where
// at this point, the default CSS file should have been loaded. But you can or
// should add the CSS rule to your custom CSS file; just make sure it\'s loaded
// *after* the default CSS file.
add_action( \'admin_enqueue_scripts\', function(){
$css = <<<EOT
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
content: \' \';
background: url(\'https://png.icons8.com/dusk/2x/e-commerce.png\') no-repeat center;
background-size: contain;
}
EOT;
wp_add_inline_style( \'woocommerce_admin_menu_styles\', $css );
}, 11 );
注:该
menu.css
文件已注册并在中排队
WC_Admin_Assets::admin_styles()
句柄/名称为
woocommerce_admin_menu_styles
.