how to make custom sub menu admin wordpress dev

To create a custom sub-menu in the WordPress admin, you can follow these steps:

  1. Open your theme's functions.php file. This file is typically located in your theme's folder.

  2. Start by creating a function that will add the custom sub-menu. You can use the add_submenu_page function to achieve this. Here's an example:

function custom_submenu_page() {
    add_submenu_page(
        'options-general.php', // Parent menu slug
        'Custom Submenu', // Page title
        'Custom Submenu', // Menu title
        'manage_options', // Capability required to access the page
        'custom-submenu', // Menu slug
        'custom_submenu_callback' // Callback function to display the page content
    );
}
  1. Next, you need to create the callback function that will display the content of the custom sub-menu. This function will be called by the add_submenu_page function. Here's an example:
function custom_submenu_callback() {
    echo '<div class="wrap">';
    echo '<h1>Custom Submenu</h1>';
    echo '<p>This is the content of the custom sub-menu.</p>';
    echo '</div>';
}
  1. Now, you need to hook the custom_submenu_page function to a WordPress action. The admin_menu action is commonly used for this purpose. Add the following code to your functions.php file:
add_action('admin_menu', 'custom_submenu_page');
  1. Save the functions.php file and upload it to your WordPress theme directory.

  2. Once you have completed the above steps, you should now see a new sub-menu item called "Custom Submenu" under the "Settings" menu in the WordPress admin.

That's it! You have successfully created a custom sub-menu in the WordPress admin. You can modify the code as needed to customize the menu title, content, and other parameters according to your requirements.