Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1130349
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionHow can I change the menu icon (coming from external plugins, like WooCommerce) in wp-admin area with custom icon? (The menu-item is actually post-type, so there should be some register_post_type command i think).
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionHow can I change the menu icon (coming from external plugins, like WooCommerce) in wp-admin area with custom icon? (The menu-item is actually post-type, so there should be some register_post_type command i think).
2 Answers
Reset to default 1WooCommerce styles the icon via this CSS file: woocommerce/assets/css/menu.css, and here's the corresponding code (pretty-printed or actually, I copied it from woocommerce/assets/css/menu.scss):
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
font-family: 'WooCommerce' !important;
content: '\e03d';
}
So you can change the font-family and the content (and other) properties to suit your custom icon.
Below is an example of customizing the icon by changing it to use a 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/dusk/2x/e-commerce.png') no-repeat center;
background-size: contain;
}
EOT;
wp_add_inline_style( 'woocommerce_admin_menu_styles', $css );
}, 11 );
Note: The menu.css file is registered and queued in WC_Admin_Assets::admin_styles() with the handle/name of woocommerce_admin_menu_styles.
to add a custom image, you can use this code. the original image is set with CSS then you have to add custom CSS to remove that.
add_action("admin_menu", function () {
foreach ($GLOBALS["menu"] as $position => $tab) {
if ("woocommerce" === $tab["2"]) {
$GLOBALS["menu"][$position][6] = "http://server/image.png";
break;
}
}
});
Closed. This question is off-topic. It is not currently accepting answers.
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionHow can I change the menu icon (coming from external plugins, like WooCommerce) in wp-admin area with custom icon? (The menu-item is actually post-type, so there should be some register_post_type command i think).
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 6 years ago.
Improve this questionHow can I change the menu icon (coming from external plugins, like WooCommerce) in wp-admin area with custom icon? (The menu-item is actually post-type, so there should be some register_post_type command i think).
2 Answers
Reset to default 1WooCommerce styles the icon via this CSS file: woocommerce/assets/css/menu.css, and here's the corresponding code (pretty-printed or actually, I copied it from woocommerce/assets/css/menu.scss):
#adminmenu #toplevel_page_woocommerce .menu-icon-generic div.wp-menu-image::before {
font-family: 'WooCommerce' !important;
content: '\e03d';
}
So you can change the font-family and the content (and other) properties to suit your custom icon.
Below is an example of customizing the icon by changing it to use a 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/dusk/2x/e-commerce.png') no-repeat center;
background-size: contain;
}
EOT;
wp_add_inline_style( 'woocommerce_admin_menu_styles', $css );
}, 11 );
Note: The menu.css file is registered and queued in WC_Admin_Assets::admin_styles() with the handle/name of woocommerce_admin_menu_styles.
to add a custom image, you can use this code. the original image is set with CSS then you have to add custom CSS to remove that.
add_action("admin_menu", function () {
foreach ($GLOBALS["menu"] as $position => $tab) {
if ("woocommerce" === $tab["2"]) {
$GLOBALS["menu"][$position][6] = "http://server/image.png";
break;
}
}
});
本文标签: functionsHow to change menu icon which is overriden (ie by WooCommerce)
版权声明:本文标题:functions - How to change menu icon which is overriden (i.e. by WooCommerce) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749063472a2310454.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论