如何更改自定义插件的默认图标?

时间:2013-02-02 作者:Bhuvnesh Gupta

我制作了一个自定义插件POLL . 当我激活它时,默认图标会出现在侧边栏上。我想更改此默认图标。这是我写的代码init.php 文件

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\';
}
我搜索了它,但没有自定义主题的结果:(所以我在这里问。提前谢谢!!!!!)!!!!!!

2 个回复
最合适的回答,由SO网友:Rajeev Vyas 整理而成

仔细查看add\\u menu\\u页面挂钩,它提供了用于提供图标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\' 
);

SO网友:Max Yudin

add_menu_page()$icon_url 参数图标大小应为16x16px。

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

结束

相关推荐

从非核心php文件访问BloInfo、Get_Option和plugins_url

我正在创建一个插件,插件目录中有一个php文件,可以通过自定义重写url直接访问该文件。我需要这个文件能够使用标题中提到的三个功能。目前,我正在包括wp负载。php文件,它使我能够访问所有这些函数。然而,我一直在读到不应该包括wp负载,因为它可能不总是在同一个位置,而且它包括可能不需要的wordpress文件。这就是我如何包含wp负载:$wp_base = explode($_SERVER[\'PHP_SELF\'], $_SERVER[\'SCRIPT_FILENAME\']); require