The first step is to create a menu entry with the add_menu_page() function. Below is a full example:
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'myplugin/myplugin-admin-page.php', 'myplguin_admin_page', 'dashicons-tickets', 6 );
}
The function takes seven arguments. The first one is the page title, which defines the title tag; it is shown in the tab title, not on screen.
The second argument is the title that shows up in the menu.
Argument three is the capability required to access the menu. This can be used to restrict it to only admins, editors or authors.
Argument four is the menu slug, which is essentially used as the URL of the page.
Argument five is the function, which will handle the content of the page.
The next argument is the icon url. This can accept a number of formats. If a URL to an image is given the image will be used. We can also use Dashicons, which are built into WordPress, or even SVG.
The last argument defines where the menu will be placed. Argument five indicated the posts so I’ve used six to put this menu entry just underneath. Take a look at the Codex to see exactly what number to use for your desired position.
The next step is to create some content. All you need to do is create the function defined in argument five and echo some content. Here’s a very simple example we can start with:
function myplguin_admin_page(){
?>
<div class="wrap">
<h2>Welcome To My Plugin</h2>
</div>
<?php
}
add_action( 'admin_menu', 'my_admin_menu' );
function my_admin_menu() {
add_menu_page( 'My Top Level Menu Example', 'Top Level Menu', 'manage_options', 'myplugin/myplugin-admin-page.php', 'myplguin_admin_page', 'dashicons-tickets', 6 );
}
The function takes seven arguments. The first one is the page title, which defines the title tag; it is shown in the tab title, not on screen.
The second argument is the title that shows up in the menu.
Argument three is the capability required to access the menu. This can be used to restrict it to only admins, editors or authors.
Argument four is the menu slug, which is essentially used as the URL of the page.
Argument five is the function, which will handle the content of the page.
The next argument is the icon url. This can accept a number of formats. If a URL to an image is given the image will be used. We can also use Dashicons, which are built into WordPress, or even SVG.
The last argument defines where the menu will be placed. Argument five indicated the posts so I’ve used six to put this menu entry just underneath. Take a look at the Codex to see exactly what number to use for your desired position.
The next step is to create some content. All you need to do is create the function defined in argument five and echo some content. Here’s a very simple example we can start with:
function myplguin_admin_page(){
?>
<div class="wrap">
<h2>Welcome To My Plugin</h2>
</div>
<?php
}
No comments:
Post a Comment