The abcon/settings/menu_parent hook provides a flexible way for developers to control where the plugin’s admin menu appears in the WordPress admin interface. Instead of appearing as a top-level menu item, you can place it under any existing WordPress admin menu, such as Appearance, Plugins, Tools, or Settings. This is particularly useful for organizing your admin interface.
Example 1: Place Menu Under Appearance
If you want to place the menu under the Appearance menu, you can use the following code snippet. This code should be added to your theme’s functions.php file or a custom plugin:
function custom_abcon_menu_under_appearance($parent) {
return 'themes.php'; // Appearance menu
}
add_filter('abcon/settings/menu_parent', 'custom_abcon_menu_under_appearance');
By returning 'themes.php', the menu will appear as a submenu under the Appearance menu, keeping your block-related settings organized with theme customization options.
Example 2: Place Menu Under Settings
You can also place the menu under the Settings menu. For example, if you want to group it with other site configuration options, you can use the following code:
function custom_abcon_menu_under_settings($parent) {
return 'options-general.php'; // Settings menu
}
add_filter('abcon/settings/menu_parent', 'custom_abcon_menu_under_settings');
This code places the menu under the Settings menu, making it easy to find alongside other configuration options.
Example 3: Place Menu Under Plugins
If you prefer to keep the menu with other plugin management tools, you can place it under the Plugins menu:
function custom_abcon_menu_under_plugins($parent) {
return 'plugins.php'; // Plugins menu
}
add_filter('abcon/settings/menu_parent', 'custom_abcon_menu_under_plugins');
This keeps all plugin-related settings in one convenient location.
Example 4: Place Menu Under Tools
For developer-focused workflows, you might want to place the menu under the Tools menu:
function custom_abcon_menu_under_tools($parent) {
return 'tools.php'; // Tools menu
}
add_filter('abcon/settings/menu_parent', 'custom_abcon_menu_under_tools');
This is ideal for keeping block controls with other developer tools.
Available Parent Menu Slugs
Here are some common WordPress admin menu slugs you can use:
'themes.php'– Appearance'plugins.php'– Plugins'tools.php'– Tools'options-general.php'– Settings'edit.php'– Posts'edit.php?post_type=page'– Pages'upload.php'– Media'users.php'– Users
Default Behavior
If you don’t use this filter (or return null/false), the menu will appear as a top-level menu item, which is the default behavior. This keeps block controls easily accessible when working with Gutenberg blocks.
Combining with Other Hooks
You can combine this hook with abcon/settings/show_admin to control both visibility and location:
// Only show menu to administrators, and place it under Settings
function custom_abcon_menu_logic($show_menu) {
if (!current_user_can('administrator')) {
return false;
}
return $show_menu;
}
add_filter('abcon/settings/show_admin', 'custom_abcon_menu_logic');
function custom_abcon_menu_location($parent) {
return 'options-general.php'; // Settings
}
add_filter('abcon/settings/menu_parent', 'custom_abcon_menu_location');
This code checks the user’s role and only shows the menu to administrators, while also placing it under the Settings menu, keeping block control settings organized and secure.
Note: When using this hook, ensure the parent menu slug is valid. Invalid slugs may prevent the menu from appearing. The menu will function the same way whether it’s top-level or under a parent menu, allowing you to manage all your Gutenberg block controls and settings from the chosen location.