1

I am filtering the menu_order hook (codex link -> http://codex.wordpress.org/Plugin_API/Filter_Reference/menu_order) to change the order of my links in the admin menu. Currently the ordering will not work on slugs that begin with admin.php, so a settings page with the slug "admin.php?page=custom_settings_page" will just go to the bottom of the list. Anyone know of a workaround for this?

//change admin menu order
add_filter('custom_menu_order', 'my_custom_menu_order'); // Activate custom_menu_order
add_filter('menu_order', 'my_custom_menu_order');

function my_custom_menu_order($menu_ord){

if(!$menu_ord) return true;
return array(
    'index.php', //dashboard
    'separator1', //first separator
    'edit.php', //posts
    'edit.php?post_type=custom_post_type1', //custom post type 1
    'edit.php?post_type=custom_post_type2', //custom post type 2
    'edit.php?post_type=custom_post_type3', //custom post type 3
    'upload.php', //media
    'separator2', //second separator
    'admin.php?page=gf_edit_forms', //THIS GOES TO THE BOTTOM
    'edit.php?post_type=page', //pages
    'edit-comments.php', //comments
    'separator-last', //last separator
    'themes.php', //appearance
    'admin.php?page=custom_settings_page', //THIS GOES TO THE BOTTOM
    'plugins.php', //plugins
    'users.php', //users
    'tools.php', //tools
    'options-general.php' //WordPress options
);

}
1
  • 1
    Please add your code to the question so it can be easily looked into by others.
    – Rarst
    Dec 11, 2013 at 13:59

1 Answer 1

3

Remove 'admin.php?page=' from those values.

'admin.php?page=custom_settings_page' should be 'custom_settings_page'

'admin.php?page=gf_edit_forms' should be 'gf_edit_forms'

Values that start with admin.php only have their parameter set in the global default menu order array (global $default_menu_order).

So when the sort occurs between your custom menu order array and the global default menu menu order array, it won't correctly match the entries that start with admin.php.

The default behavior is for anything that's not in your custom array to be added to the bottom.

Corrected code:

//change admin menu order
add_filter('custom_menu_order', 'my_custom_menu_order'); // Activate custom_menu_order
add_filter('menu_order', 'my_custom_menu_order');

function my_custom_menu_order($menu_ord){

    if(!$menu_ord) return true;
    return array(
        'index.php', //dashboard
        'separator1', //first separator
        'edit.php', //posts
        'edit.php?post_type=custom_post_type1', //custom post type 1
        'edit.php?post_type=custom_post_type2', //custom post type 2
        'edit.php?post_type=custom_post_type3', //custom post type 3
        'upload.php', //media
        'separator2', //second separator
        'gf_edit_forms', //fixed
        'edit.php?post_type=page', //pages
        'edit-comments.php', //comments
        'separator-last', //last separator
        'themes.php', //appearance
        'custom_settings_page', //fixed
        'plugins.php', //plugins
        'users.php', //users
        'tools.php', //tools
        'options-general.php' //WordPress 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.