FEATURE Reordering admin menu for backend

This commit is contained in:
Antoine M 2026-05-07 17:55:09 +02:00
parent 86ad3dec9a
commit a0e4adc705

View File

@ -279,3 +279,53 @@ function carhop_hide_default_post_type()
remove_menu_page('edit-comments.php');
}
add_action('admin_menu', 'carhop_hide_default_post_type');
/* ----------------------------------------------------------------------
REORDER ADMIN MENU & POST TYPE ORDER ON MENU BAR
------------------------------------------------------------------------*/
/**
* Filters WordPress' default menu order
*/
function carhop_new_admin_menu_order($menu_order)
{
// define your new desired menu positions here
// for example, move 'upload.php' to position #9 and built-in pages to position #1
$new_positions = array(
'edit.php?post_type=auteurs' => 3,
'edit.php?post_type=actualites' => 4,
'edit.php?post_type=analyses-etudes' => 5,
'edit.php?post_type=dbmob' => 6,
'edit.php?post_type=outils-pedagogiques' => 7,
'edit.php?post_type=fonds-archives' => 8,
'edit.php?post_type=expositions' => 9,
'edit.php?post_type=activites' => 10,
'carhop-presse' => 11,
'edit.php?post_type=recherches' => 12,
'edit.php?post_type=reportages' => 13,
'edit.php?post_type=page' => 14,
'upload.php' => 15,
'theme-general-settings' => 16,
'rank-math' => 20,
);
// helper function to move an element inside an array
function carhop_move_element(&$array, $a, $b)
{
$out = array_splice($array, $a, 1);
array_splice($array, $b, 0, $out);
}
// traverse through the new positions and move
// the items if found in the original menu_positions
foreach ($new_positions as $value => $new_index) {
if ($current_index = array_search($value, $menu_order)) {
carhop_move_element($menu_order, $current_index, $new_index);
}
}
return $menu_order;
};
add_action('admin_menu', function () {
add_filter('menu_order', 'carhop_new_admin_menu_order');
add_filter('custom_menu_order', '__return_true');
});