add_menu_page中的重复标签

时间:2012-06-13 08:05:54

标签: wordpress duplicates customization admin

我已经为主题自定义创建了一个函数。

function create_theme_option() {

        add_menu_page(  'Manage Options', //Page Title 

                        'Theme Option', //WP Administrator Menu Title

                        'manage_options', //

                        'theme-options', //Link to a page to your Administration Area

                        'deploy_theme_options', //Function Name

                        get_template_directory_uri() . '/Plugins/Background Changer/images/icons/icon.png',//Menu Icon 

                        99);

        add_submenu_page("theme-options", "Theme Settings", "Theme Settings", 1, "theme-settings", "theme_settings");

        add_submenu_page("theme-options", "Manage Header", "Manage Header", 1, "manage-header", "manage_header");

        add_submenu_page("theme-options", "Social Media", "Social Media Links", 1, "social-media", "social_media");

        add_submenu_page("theme-options", "Catalog Manager", "Catalog Manager", 1, "catalog-manager", "catalog_manager");

    }

但是我注意到在“主题选项”标签之后,旁边会出现另一个文本作为“主题选项”。检查下面的图片:

http://leojarina.info/stock-data/images/screenshot.jpg

我该如何解决这个问题?请帮忙!

5 个答案:

答案 0 :(得分:8)

@Basharat非常接近。这是我在插件中使用的一种更清洁的方式:

add_menu_page(
    '',                     // No need to have this
    'My Plugin',            // Menu Label
    'manage_options',
    'my_plugin_settings',   // (*) Shared slug
    'your_function',
    plugins_url('myplugin/images/icon.png'),
    81
);

add_submenu_page(
    'my_plugin_settings',   // (*) Shared slug
    'My Plugin Settings',   // Subpage Title
    'Settings',             // Submenu Label
    'manage_options',
    'my_plugin_settings',   // (*) Shared slug
    'your_function'
);

来源:咖啡,反复试验;)

答案 1 :(得分:2)

要解决此问题,您可以使用remove_submenu_page, http://codex.wordpress.org/Function_Reference/remove_submenu_page

示例:

remove_submenu_page('my-menu-slug','my-menu-slug')

答案 2 :(得分:0)

我认为你应该检查不应该是99的能力参数

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

答案 3 :(得分:0)

请使用以下内容删除子菜单中菜单的重复条目。

<?php 
/* Add top level menu */
add_menu_page(
    'MyTheme', 
    'MyTheme Menu Label',
    'edit_themes', 
    'theme_admin',        // menu slug
    'functions.php',        // function
    get_bloginfo('template_directory') .'/img/favicon.png',
    31
);

/* remove duplicate menu hack */
add_submenu_page(
    'theme_admin',        // parent slug, same as above menu slug
    '',        // empty page title
    '',        // empty menu title
    'edit_themes',        // same capability as above
    'theme_admin',        // same menu slug as parent slug
    'functions.php',        // same function as above
}
?>

这不是太干净,但是隐藏重复子菜单的唯一方法。

<强>参考: https://wordpress.stackexchange.com/questions/52675/how-to-remove-duplicate-link-from-add-menu-page

答案 4 :(得分:0)

我找到的唯一工作方式是将add_menu_page $功能设置为未知,所以类似'unknown',这将隐藏页面或子菜单,但菜单仍将显示在左侧。