Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!!!!!!

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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' 
);
share|improve this answer
    
thanks!!!!! Rajeev for your answer and sorry for I should check first. Thanks again –  Bhuvnesh Gupta Feb 2 '13 at 11:18
add comment

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.

share|improve this answer
    
thanks for size information :) –  Bhuvnesh Gupta Feb 2 '13 at 11:19
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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