0

I am writing a plugin (Github Link) and have trouble setting up the titles of the admin menu.

I defined a top header menu with add_menu_page (link to code, same as below) and 2 children with add_submenu_page, but I get 4 lines in the Admin menu, the main one, then that one again (with the same link target) in small and then the 2 children.

add_action('admin_menu', 'unc_gallery_admin_menu');
function unc_gallery_admin_menu() {
    // the main page where we manage the options
    add_menu_page(
        'Uncovery Gallery Options', // $page_title,
        'Uncovery Gallery', // $menu_title,
        'manage_options', // $capability,
        'unc_gallery_admin_menu', // $menu_slug,
        'unc_gallery_options' // $function, $icon_url, $position
    );
    // where we upload images
    $upload_page_hook_suffix = add_submenu_page(
        'unc_gallery_admin_menu', // $parent_slug
        'Upload Images',  // $page_title
        'Upload Images', // $menu_title
        'manage_options', // capability, manage_options is the default
        'unc_gallery_admin_upload', // menu_slug
        'unc_uploads_form' // function
    );
    add_action('admin_print_scripts-' . $upload_page_hook_suffix, 'unc_gallery_admin_add_css_and_js');
    // where we list up all the images
    $view_page_hook_suffix = add_submenu_page(
        'unc_gallery_admin_menu', // $parent_slug
        'View Images',  // $page_title
        'View Images', // $menu_title
        'manage_options', // capability, manage_options is the default
        'unc_gallery_admin_view', // menu_slug
        'unc_gallery_admin_display_images' // function
    );
    add_action('admin_print_scripts-' . $view_page_hook_suffix, 'unc_gallery_admin_add_css_and_js');    
}

enter image description here

How can I either change the title of the 2nd "Uncovery Gallery" or preferably remove it?

thanks!

1
  • Please edit your question and add the relevant code to it Feb 16, 2016 at 7:57

2 Answers 2

1

You can change the first Submenu text with the following script:

function __test_menu() {
    global $submenu;
    //var_dump($submenu); //check yourself
    $submenu['unc_gallery_admin_menu'][0][0] = __( 'Test', 'textdomain' );
}
add_action( 'admin_menu', '__test_menu' );

Please note, your plugin is error-prone, throwing warning messages. Always develop things with WP_DEBUG to true. And don't write hardcore texts, better write them in gettext functions. i.e. write __( 'Test', 'textdomain' ); instead of 'Test';. It will make your plugin translation-ready. Good luck.

1
  • Thanks for the hints, found the 2 warnings and fixed them.
    – uncovery
    Feb 16, 2016 at 8:35
1

You can use.

 add_submenu_page('unc_gallery_admin_menu', '', '', 'read','unc_gallery_admin_menu', 'unc_gallery_options');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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