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

Ultimate Guide to Custom Meta Boxes in WordPress

In WordPress, `add_meta_boxes` is an action hook that allows developers to add custom meta boxes to different post types’ edit screens. Meta boxes are additional sections on the post editor screen where you can add and display custom fields or other types of data related to the post.

Shortcodes included with Dokan

Dokan is a popular multi-vendor marketplace plugin for WooCommerce that allows you to create and manage a marketplace where multiple vendors can sell their products. Dokan provides several shortcodes that you can use to display various elements and functionalities on your marketplace pages. Here are some of the essential shortcodes provided by Dokan:

Add Admin User in WordPress By FTP

Creating an admin user in WordPress through an FTP client is not a direct method since user accounts are managed through the WordPress database and not through files on the server. To add an admin user, you’ll need to use a different approach. Here’s how you can do it: