how to make custom sub menu admin wordpress dev
To create a custom sub-menu in the WordPress admin, you can follow these steps:
Open your theme's
functions.php
file. This file is typically located in your theme's folder.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
);
}
- 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>';
}
- 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 yourfunctions.php
file:
add_action('admin_menu', 'custom_submenu_page');
Save the
functions.php
file and upload it to your WordPress theme directory.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.