How To Add Menu In WordPress Admin Panel

To add a custom menu in the WordPress admin panel, you can use the `add_menu_page()` or `add_submenu_page()` functions. Here’s a step-by-step guide on how to add a menu in the WordPress admin panel:

1. Open the theme’s functions.php file in your WordPress theme directory (or create a new plugin file if you prefer).
2. Add the following code to the file:

 

// Add a top-level menu page
function custom_menu_page() {
    add_menu_page(
        'Custom Menu',    // Page title
        'Custom Menu',    // Menu title
        'manage_options', // Required capability to access the menu page
        'custom-menu',    // Menu slug
        'custom_menu_callback', // Callback function to render the menu page
        'dashicons-admin-generic', // Menu icon (optional)
        25   // Menu position (optional)
    );
}
add_action('admin_menu', 'custom_menu_page');

// Callback function to render the menu page
function custom_menu_callback() {
    // Your menu page content goes here
    echo '<div class="wrap">';
    echo '<h1>Custom Menu</h1>';
    echo '<p>Welcome to the custom menu page!</p>';
    echo '</div>';
}

 

3. Save the changes and upload the modified functions.php file (or the plugin file) back to your server.

This code adds a top-level menu page with the title “Custom Menu” to the WordPress admin panel. The `add_menu_page()` function accepts several parameters, including the page title, menu title, required capability, menu slug, callback function to render the menu page, menu icon (optional), and menu position (optional).

The `custom_menu_callback()` function is the callback function that renders the content of the menu page. You can modify this function and add your own HTML and PHP code to customize the menu page content.

After making these changes, you should see a new menu item labeled “Custom Menu” in the WordPress admin panel, and when clicked, it will display the content defined in the `custom_menu_callback()` function.

Categories
Scroll to Top

Request A Quote