Reorder custom submenu item

Got it, thanks to cjbj‘s help, I was able to get the final solution:

add_filter( 'custom_menu_order', 'submenu_order' );
function submenu_order( $menu_order ) {
    # Get submenu key location based on slug
    global $submenu;
    $settings = $submenu['options-general.php'];
    foreach ( $settings as $key => $details ) {
        if ( $details[2] == 'blogging' ) {
            $index = $key;
        }
    }
    # Set the 'Blogging' menu below 'General'
    $submenu['options-general.php'][11] = $submenu['options-general.php'][$index];
    unset( $submenu['options-general.php'][$index] );
    # Reorder the menu based on the keys in ascending order
    ksort( $submenu['options-general.php'] );
    # Return the new submenu order
    return $menu_order;
}

Leave a Comment

tech