Last Updated on July 5 2022 by dhimaskirana
In this tutorial, I will share about how to create a custom WordPress Admin page.
Create Top Level Menu
First, we need to create a top-level menu using the add_menu_page function and place it on the admin_menu action.
// Create Menu
add_action('admin_menu', function () {
add_menu_page('Title Page', 'Title on Menu', 'manage_options', 'your-slug-page', 'page_callback', 'dashicons-grid-view', 90);
});
Create Page Callback
Next, we need to create page content. On add_menu_page, we define the page_callback function to output the menu. Let’s create the page output.
// Create Page Content
function page_callback() { ?>
<div class="wrap">
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
<p>Hi, this is a custom WordPress Admin page.</p>
</div>
<?php }
If your HTML content is too long, I suggest you make a separate file for the page content. And then load it to your callback.
// Create Page Content
function page_callback() {
include(plugin_dir_path(__FILE__) . 'custom-page-admin.php');
}
Good luck.