6

I made a custom plugin for POLL . When I activate it, default icon is coming there on sidebar. I want to change this default icon. Here is my code which I wrote in init.php file.

add_action('admin_menu', 'mt_add_pages');



// action function for above hook
function mt_add_pages() {

    // Add a new top-level menu (ill-advised):
    add_menu_page(__('Poll','menu-test'), __('Poll','menu-test'), 'manage_options', 'manage-polls', 'poll_page' );

    // Add a submenu to the custom top-level menu:
    add_submenu_page('manage-polls', __('Add New Poll','menu-test'), __('Add New Poll','menu-test'), 'manage_options', 'add-poll', 'add_new_poll_page');


}



// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function poll_page() {
    if (!current_user_can('manage_options'))
    {
      wp_die( __('You do not have sufficient permissions to access this page.') );
    }
    echo "<br/>";
    echo "<div>";
    echo '<div style="float:left;"><img width="20" height = "20" src="'.site_url().'/wp-content/plugins/poll/images/poll_red.png" /></div>';
    echo "</div>";
    echo "<h2>" . __( 'Manage Polls', 'menu-test' ) . "</h2>";

    include_once 'manage-polls.php';
}

// mt_sublevel_page() displays the page content for the first submenu
// of the custom Test Toplevel menu
function add_new_poll_page() {
    if (!current_user_can('manage_options'))
    {
      wp_die( __('You do not have sufficient permissions to access this page.') );
    }
    echo "<br/>";
    echo "<div>";
    echo '<div style="float:left;"><img width="20" height = "20" src="'.site_url().'/wp-content/plugins/poll/images/poll_red.png" /></div>';
    echo "</div>";
    include_once 'poll_form.php';
}

I searched it but results are not coming for custom theme. :( so I am asking here. Thanks in advance!!!!!!

5

Take a close look at add_menu_page hook, it provides argument to supply with icon url

<?php 
add_menu_page( 
    $page_title, 
    $menu_title, 
    $capability, 
    $menu_slug, 
    $function, 
    $icon_url, 
    $position 
); 

http://codex.wordpress.org/Function_Reference/add_menu_page

add_menu_page(
    __('Poll','menu-test'), 
    __('Poll','menu-test'), 
    'manage_options', 
    'manage-polls', 
    'poll_page',
    'plugins_folder Or Theme folder url/icon.png' 
);
1
  • 1
    This is great and all, but one thing that the codex fails to show is: 1) what should the icon size be. 2) How do you incorporate an SVG that will match the color scheme (it only says data type but doesn't specify exactly how or the approach). 3) Making the icon a :before attribute like everything else. – Majed Jun 27 '19 at 14:40
6

add_menu_page() has the $icon_url parameter. Icon size should be 16x16px.

add_menu_page(
    __( 'Poll', 'example_textdomain' ),
    __( 'Poll', 'example_textdomain' ),
    'manage_options',
    'manage-polls',
    'poll_page',
    plugin_dir_url( __FILE__ ) . 'images/poll_red.png'
);

See add_menu_page parameters.

2
  • can you tell me what is 'menu-test' in it. Because I want to change Name of submenu. When I running the above code it is creating two submenu under POLL one is Poll and another is Add New Poll but I want Manage Polls and Add New Poll – Bhuvnesh Gupta Feb 2 '13 at 11:30
  • 1
    It's textdomain for localization. See How To Localize WordPress Themes and Plugins. Actually, I've copied a part of your code. – Max Yudin Feb 2 '13 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.