Skip to content

Instantly share code, notes, and snippets.

@aaronsummers
Last active April 16, 2018 08:45
Show Gist options
  • Save aaronsummers/bea8e585f0da0772b73a09ec956f919e to your computer and use it in GitHub Desktop.
Save aaronsummers/bea8e585f0da0772b73a09ec956f919e to your computer and use it in GitHub Desktop.
Debug wordpress admin sidebar

Thanks to this post

You need to use the right hooks (which are not always the same as the URLs/slugs), and it doesn't hurt to use a hook that runs later (e.g., admin_init):

add_action( 'admin_init', 'wpse_136058_remove_menu_pages' );

function wpse_136058_remove_menu_pages() {

    remove_menu_page( 'edit.php?post_type=acf' );
    remove_menu_page( 'wpcf7' );
}

You can use the following to debug:

add_action( 'admin_init', 'wpse_136058_debug_admin_menu' );

function wpse_136058_debug_admin_menu() {

    echo '<pre>' . print_r( $GLOBALS[ 'menu' ], TRUE) . '</pre>';
}

This gives (for my setup) the following for the Contact Form 7 plugin menu page:

[27] => Array
        (
            [0] => Formular
            [1] => wpcf7_read_contact_forms
            [2] => wpcf7
            [3] => Contact Form 7
            [4] => menu-top menu-icon-generic toplevel_page_wpcf7 menu-top-last
            [5] => toplevel_page_wpcf7
            [6] => none
        )

The array element with key 2 is what you are looking for: wpcf7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment