I am attempting to create a WordPress plugin which allows the client to use for help and other resources in a friendly interface. It would be desired if I could have guidance on creating a WordPress plugin with a main dashboard menu and submenus on it which can contain HTML content. As I am a new to WordPress Development, I found it hard to understand the WP Codex.
This is the plugin code:
/** add menu. */
add_action( 'admin_menu', 'my_plugin_menu', 'my_magic_function' );
add_submenu_page( 'my_plugin_menu', 'Page title', 'Sub-menu title', 'manage_options', 'my-submenu-handle', 'my_magic_function');
function my_plugin_menu() {
add_options_page( 'My Plugin Options', 'My Plugin', 'manage_options', 'my-unique-identifier', 'my_plugin_options' );
}
function my_plugin_menu() {
add_options_page( 'Submenu', 'My Plugin', 'manage_options', 'my-submenu-handle', 'my_plugin_options' );
}
/** html. */
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<p>Main page</p>';
echo '</div>';
}
function my_plugin_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<p>submenu page</p>';
echo '</div>';
}
Here is a simple example to get you started with the right code. This creates a main menu item using
add_menu_page
then attaches a submenu usingadd_submenu_page
. Both of them call a different function for the output.Notice that the
add_submenu_page
function ties into the parent menu usingcustomteam
which is the$menu_slug
ofadd_menu_page
.