In this video, I show you how to create a new menu page in the WordPress admin area. This will create a new menu item on the left hand side menu when you log into the backend.
Place this code in functions.php (of a child theme if your theme can be updated) or another globally accessible file. If you’re editing someone elses theme please see my video about creating a wordpress child theme.
The Code For Adding A Menu Page In WordPress
This is just a sample code that creates a menu page called Say Hello and outputs a simple message to the screen. We will break it down after.
add_menu_page(
'Say Hello',
'Say Hello',
'read',
'say-hello',
'do_say_hello',
'dashicons-format-chat',
999
);
function do_say_hello() {
?>
<div class="wrap">
<h1>Say Hello</h1>
<p>I just wanted to say hello to you on your new admin page!</p>
</div>
<?php
}
The function is called add_menu_page() and it has 6 parameters
- Page Title – The title of the new page
- Menu Title – The menu item text
- Capabilities – This determines who can access the newly created page (see wordpress roles and capabilities page). ‘read’ is for everyone, while something like ‘update_plugins’ would be only for administrators.
- Slug – This is the slug that shows in the url of the newly created page
- Callback Function – This is the callback function that gets executed when the page is accessed
- Icon – This is the image that shows next to the menu item (see dashicons page)
- Position – This is the number that determines where your menu page sits in the menu