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.

Related Blogs

Add same product to cart twice instead of changing quantity in Cart

By default, WooCommerce allows customers to change the quantity of a product in the cart by updating the quantity input field on the cart page. If the quantity is increased, the product will be added to the cart only once with the updated quantity. However, if you want to allow customers to add the same product multiple times as separate items in the cart, you’ll need to customize the cart behavior.

Request A Quote

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.