In WordPress, the function `add_submenu_page()` is used to add a submenu page to an existing top-level menu in the WordPress administration dashboard. This function allows developers to create custom administration pages and organize them under existing menu items.
Here's an example of how `add_submenu_page()` is used in WordPress:
```php
add_action('admin_menu', 'my_plugin_submenu');
function my_plugin_submenu() {
add_submenu_page(
'my_plugin_menu', // Parent slug
'Submenu Page', // Page title
'Submenu Page', // Menu title
'manage_options', // Capability required
'my_submenu_slug', // Menu slug
'my_submenu_callback' // Callback function
);
}
function my_submenu_callback() {
// Page content goes here
}
```
In Drupal, the concept of creating submenu links under a parent menu item is slightly different. Instead of using a specific function like `add_submenu_page()`, developers define menu links and their hierarchy in a `.links.menu.yml` file within their custom module.
Here's an example of how to define a submenu link in Drupal:
```yaml
mymodule.submenu:
title: 'Submenu Page'
parent: mymodule.main_menu
route_name: mymodule.submenu_route
description: 'Description of the submenu item'
weight: 50
```
In this example, `mymodule.main_menu` is the parent menu item defined elsewhere in the module's `.links.menu.yml` file. The submenu link `mymodule.submenu` is defined with its title, parent, route name, description, and weight.
Overall, while both WordPress and Drupal allow developers to create submenu items, they have different approaches and syntax for achieving this functionality. In WordPress, it's done programmatically using `add_submenu_page()`, while in Drupal, it's configured using YAML files and defined routes.
Comments