1. Home
  2. Docs
  3. Weblabs UI (Pro)
  4. Developers
  5. Menu Extensions

Menu Extensions

The Weblabs UI Plugin allows developers to add custom menu items under the “Extensions” section of the WordPress admin menu. This is achieved by utilizing the weblabsui_custom_menu_items filter provided by the plugin.

Steps to Add Custom Menus

  1. Hook into the weblabsui_custom_menu_items Filter:
    To add your custom menu items, you need to hook into the weblabsui_custom_menu_items filter in your plugin or theme’s functions.php file.
Code
add_filter('weblabsui_custom_menu_items', 'my_custom_menu_items');

   function my_custom_menu_items($items) {
       $items[] = [
           'Menu Title', // The title of the menu item
           'manage_options', // Capability required to access this menu
           'my_custom_menu_slug', // The slug for the menu item
           'my_custom_menu_callback', // The function to call when the menu item is clicked
           'dashicons-admin-generic' // Optional: Icon for the menu item
       ];
       return $items;
   }
  1. Define the Callback Function:
    Create the callback function that will be executed when the menu item is clicked. This function should handle the display of the content for your custom menu page.
Code
function my_custom_menu_callback() {
       echo '<h1>My Custom Menu Page</h1>';
       // Add your custom content here
   }
  1. Set Permissions:
    Ensure that the capability specified in the menu item (e.g., manage_options) is appropriate for the users who should have access to this menu.
  2. Testing:
    After implementing the above code, navigate to the WordPress admin area. You should see your custom menu item listed under the “Extensions” section. Click on it to verify that it displays the expected content.

Example

Here’s a complete example of adding a custom menu item:

Code
add_filter('weblabsui_custom_menu_items', 'my_custom_menu_items');

function my_custom_menu_items($items) {
    $items[] = [
        __('My Custom Menu', 'weblabsui'), // Menu Title
        'manage_options', // Capability
        'my_custom_menu_slug', // Menu Slug
        'my_custom_menu_callback', // Callback function
        'dashicons-admin-generic' // Icon
    ];
    return $items;
}

function my_custom_menu_callback() {
    echo '<h1>' . __('My Custom Menu Page', 'weblabsui') . '</h1>';
    // Add additional content or functionality here
}

Conclusion

By following these steps, developers can easily add custom menu items under the “Extensions” section of the Weblabs UI Plugin, enhancing the functionality and user experience of their WordPress admin interface.

How can we help?