$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>functions - How to change menu icon which is overriden (i.e. by WooCommerce)|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

functions - How to change menu icon which is overriden (i.e. by WooCommerce)

matteradmin9PV0评论
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 question

How 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).

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 question

How 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).

Share Improve this question edited Dec 27, 2018 at 23:20 T.Todua 5,8909 gold badges52 silver badges81 bronze badges asked Jul 16, 2018 at 4:47 William JeromeWilliam Jerome 1836 silver badges13 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

WooCommerce 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;
        }

    }


});
Post a comment

comment list (0)

  1. No comments so far