TaraGurung
TaraGurung

Reputation: 135

changing the icons of the wordpress dashboard menu not working

I have created a menu that displays as Theme-option in WordPress dashboard. What normally happens is we get a default icon before the name of the menu SO am trying to change it to my own icon image. My code that adds the menu using add_menu_page() WordPress function is here . But it shows something like alt "" and the icon is not displayed.

    add_action('admin_menu','my_admin_theme_menu');
    function my_admin_theme_menu(){ 
        //theme-option menu icons 
$icons='<img alt="menu-icon" src="'.plugins_url('images/theme_option.png').'">';
add_menu_page('theme-option', 'Theme-option', 'administrator','menu-    slug-id','theme_menu_callback',$icons,20);
    }

Upvotes: 0

Views: 2986

Answers (1)

Josh Davenport-Smith
Josh Davenport-Smith

Reputation: 5511

The argument for add_menu_page needs just a url to the image, not an img element that would display the image were it rendered.

You'll probably want to heed the advice from the WordPress codex here (add_menu_page parameters documentation) and use plugin_dir_url( __FILE__ ) to get the URL of your plugin directory and then add the image filename to it.

So you'd use the following code instead:

add_action('admin_menu','my_admin_theme_menu');
function my_admin_theme_menu(){ 
    $icon = plugin_dir_url( __FILE__ ) . 'images/theme_option.png';
    add_menu_page('theme-option', 'Theme-option', 'administrator','menu-slug-id', 'theme_menu_callback', $icon, 20);
}

This will work assuming the PHP file you're calling the code from is in the root of your plugin directory, and the image is in the images directory within that directory.

Upvotes: 2

Related Questions