Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
* Inject a placeholder in the WP admin menu by bumping everything else down if necessary
* @param $position int The desired position to free up
function my_free_up_menu_slot( $position ) {
global $menu;
if( !is_array( $menu ) ) {
return $menu;
// store the menu in reverse so we can iterate through it without losing anything
$my_menu = array_reverse( $menu, true );
krsort( $my_menu );
// if the slot is occupied, free it up!
if( isset( $menu[$position] ) ) {
// iterate through the (reversed) menu and increment every key
foreach( $my_menu as $my_menu_key => $my_menu_value ) {
$my_menu[$my_menu_key+1] = $my_menu[$my_menu_key];
unset( $my_menu[$my_menu_key] ); // kill the original
// back to business
$menu = array_reverse( $my_menu, true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment