Pawan Kumawat

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

Related Blogs

Delete Product Image With Product Delete In WooCommerce

In WooCommerce, when you delete a product, by default, the product images are not automatically deleted from the server to avoid accidental data loss. However, you can add a custom action to delete the product images when a product is deleted. Here’s a step-by-step guide to achieve this:

Sort A ACF Repeater Field Results

Filters the field $value after being loaded. Sort a repeater field using a function called array_multisort(). Sorting Filtering Modifying ACF results .

How To add custom product data tabs in WooCommerce

To add custom product data tabs in WooCommerce, you can use the woocommerce_product_data_tabs and woocommerce_product_data_panels hooks. These hooks allow you to add new tabs to the product edit page in the WooCommerce admin area. Here’s a step-by-step guide on how to achieve this: