Created
May 2, 2023 17:28
-
-
Save nathaningram/f30551c159b1806ac583f1ec110f1b65 to your computer and use it in GitHub Desktop.
Sort WP Admin Settings Menu Alphabetically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to sort settings menu items alphabetically | |
function ni_sort_settings_menu_items_alphabetically() { | |
global $submenu; | |
// Check if the settings menu exists | |
if (isset($submenu['options-general.php']) && is_array($submenu['options-general.php'])) { | |
// Sort the items under the settings menu alphabetically | |
usort($submenu['options-general.php'], function ($a, $b) { | |
// Ensure both array elements have the 0-index set and are strings | |
if (isset($a[0]) && isset($b[0]) && is_string($a[0]) && is_string($b[0])) { | |
return strcasecmp($a[0], $b[0]); | |
} | |
return 0; | |
}); | |
} | |
} | |
add_action('admin_menu', 'ni_sort_settings_menu_items_alphabetically', 999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment