Adding your own management menu to WordPress ① Adding a top menu
<p><span style="font-size: 12pt;">Hello, I'm Wakatchi ( <a href="https://twitter.com/wakatchi_tech">@wakatchi_tech</a> )</span></p>
<div class="wp-block-vk-blocks-balloon vk_balloon vk_balloon-position-right vk_balloon-type-speech vk_balloon-animation-none"><div class="vk_balloon_icon"><figure><img class="vk_balloon_icon_image vk_balloon_icon_image-type-normal " src="https://wakatchi.dev/wp-content/uploads/2022/07/computer01_boy.png" alt=""/><figcaption class="vk_balloon_icon_name">質問者</figcaption></figure></div><div class="vk_balloon_content_outer"><div class="vk_balloon_content has-background-color has-pale-cyan-blue-background-color "><span class="vk_balloon_content_before has-text-color has-pale-cyan-blue-color"></span><span class="vk_balloon_content_after "></span>
<p>Is there a way to save settings for a blog created with WordPress?</p>
</div></div></div>
<p><span style="font-size: 12pt;">When running a site developed with WordPress, you may want to save the site's unique settings or change the settings while operating the site.</span></p>
<p><span style="font-size: 12pt;"><span class="marker-halfYellow"><span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter"><strong>For site-specific settings, we recommend developing your own WordPress admin menu.</strong></span></span> Site setting values (parameters) can be changed by modifying the source code such as function.php using a plugin editor. However, if the source code is under version control or if the site operator is not good at coding, constant changes to the source code may not be healthy.</span></p>
<p><span style="font-size: 12pt;">You can easily create an admin menu by simply calling functions provided by WordPress. Also, unlike the front-end screen that is open to site users, the management menu does not require much design, as a simple screen for site operators is sufficient.</span></p>
<p><span style="font-size: 12pt;">In this article, we will show you how to add your own admin menu to WordPress.</span></p>
<div class="wp-block-vk-blocks-border-box vk_borderBox vk_borderBox-background-transparent has-text-color has-pale-cyan-blue-color is-style-vk_borderBox-style-solid-kado-tit-tab"><div class="vk_borderBox_title_container has-background has-pale-cyan-blue-background-color"><i class=""></i><h4 class="vk_borderBox_title"><strong><strong>This article is recommended for </strong></strong></h4></div><div class="vk_borderBox_body">
<ul class="is-style-vk-handpoint-mark wp-block-list">
<li>WordPress site developers who want to configure the entire site from the WordPress admin screen</li>
<li>WordPress theme and plugin developer</li>
</ul>
</div></div>
<div class="wp-block-vk-blocks-table-of-contents-new vk_tableOfContents vk_tableOfContents-style-default tabs"><div class="tab"><div class="vk_tableOfContents_title">目次</div><input type="checkbox" id="chck1"/><label class="tab-label vk_tableOfContents_openCloseBtn button_status button_status-open" for="chck1" id="vk-tab-label">CLOSE</label><ul class="vk_tableOfContents_list tab_content-open">
<li class="vk_tableOfContents_list_item vk_tableOfContents_list_item-h-2">
<a href="#vk-htags-79b237a7-b178-4458-b0ac-11830888f763" class="vk_tableOfContents_list_item_link">
<span class="vk_tableOfContents_list_item_link_preNumber">1. </span>
Code the WordPress admin menu with PHP
</a>
</li>
<li class="vk_tableOfContents_list_item vk_tableOfContents_list_item-h-2">
<a href="#vk-htags-72e0cca3-da51-436f-88f5-8a7499bd92cb" class="vk_tableOfContents_list_item_link">
<span class="vk_tableOfContents_list_item_link_preNumber">2. </span>
Add an admin menu to WordPress
</a>
</li>
<li class="vk_tableOfContents_list_item vk_tableOfContents_list_item-h-3">
<a href="#vk-htags-52d904d7-fa2e-4749-a6a3-5cc413a37a3d" class="vk_tableOfContents_list_item_link">
<span class="vk_tableOfContents_list_item_link_preNumber">2.1. </span>
Add top menu
</a>
</li>
<li class="vk_tableOfContents_list_item vk_tableOfContents_list_item-h-2">
<a href="#vk-htags-d3983128-cd7b-4079-b393-498f6f66e2bb" class="vk_tableOfContents_list_item_link">
<span class="vk_tableOfContents_list_item_link_preNumber">3. </span>
summary
</a>
</li>
</ul></div></div>
<h2 class="wp-block-heading" id="vk-htags-79b237a7-b178-4458-b0ac-11830888f763">Code the WordPress admin menu with PHP</h2>
<div class="wp-block-image">
<figure class="aligncenter size-full is-resized"><img src="https://wakatchi.dev/wp-content/uploads/2025/01/ben-griffiths-bj6enzdmsdy-unsplash-scaled.jpeg" alt="" class="wp-image-1782" style="width:835px;height:auto"/></figure></div>
<p><span style="font-size: 12pt;">WordPress admin menus are coded in PHP using functions provided by WordPress. After a quick look, there aren't any plugins that allow you to flexibly configure the WordPress admin menu without any coding.</span></p>
<p><span style="font-size: 12pt;">Using the admin menu is useful not only when developing WordPress themes and plugins, but also when developing a single site. As mentioned above, settings related to site operation can be written in source code, such as function.php, but <span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter"><strong><span class="marker-halfRed">it is not healthy to constantly change settings related to site behavior in source code</span></strong></span>. Source code and configuration values should be separated.</span></p>
<div class="wp-block-vk-blocks-balloon vk_balloon vk_balloon-position-left vk_balloon-type-speech vk_balloon-animation-none"><div class="vk_balloon_icon"><figure><img class="vk_balloon_icon_image vk_balloon_icon_image-type-normal " src="https://wakatchi.dev/wp-content/uploads/2022/07/wakatchi_icon_2.jpg" alt=""/><figcaption class="vk_balloon_icon_name">わかっち</figcaption></figure></div><div class="vk_balloon_content_outer"><div class="vk_balloon_content has-background-color has-luminous-vivid-amber-background-color vk_balloon_content_fullwidth"><span class="vk_balloon_content_before has-text-color has-luminous-vivid-amber-color"></span><span class="vk_balloon_content_after "></span>
<p>The key to deciding whether to develop a management menu is who (developer? operator?) will be changing the site settings.</p>
</div></div></div>
<p>Add the admin menu to WordPress using <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-black-color"><strong><span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter">add_menu_page</span></strong></mark>(). Let's take a closer look here.</p>
<h2 class="wp-block-heading" id="vk-htags-72e0cca3-da51-436f-88f5-8a7499bd92cb">Add an admin menu to WordPress</h2>
<p>The WordPress admin menu is the user interface displayed on the WordPress admin screen. You can add themes, plugins, and optional pages for your site.</p>
<p>The management menu has a top menu and submenus. Whether to use the top menu or a submenu is decided based on the characteristics of the plug-in and the needs of the user. Adding a top menu will give you your own top menu on the left side of the WordPress admin console. If you only add a submenu, the existing top menu will have its own submenu.</p>
<p>In this article, we will introduce a sample that adds a management menu called "Test Top Menu" to the WordPress management console and displays a screen called "Test Option Settings" as shown below.</p>
<div class="wp-block-vk-blocks-alert vk_alert alert alert-info has-alert-icon"><div class="vk_alert_icon"><div class="vk_alert_icon_icon"><i class="fa-solid fa-circle-info" aria-hidden="true"></i></div><div class="vk_alert_icon_text"><span>Information</span></div></div><div class="vk_alert_content">
<p>Here is a screenshot of the WordPress Dashboard (in Japanese). However, for multilingual purposes, the following Japanese text has been translated as follows:</p>
<ul class="wp-block-list">
<li>管理メニュータイトル → admin menu title</li>
<li>テスト用トップメニュー → Test Top Menu</li>
<li>テスト用オプション設定 → Test Option Settings</li>
</ul>
</div></div>
<figure class="wp-block-image"><img src="https://wakatchi.dev/wp-content/uploads/2023/01/wordpress-admin-menu-top-menu-ex_01.png" alt="" class="wp-image-527"/></figure>
<p>The above screen can be incorporated into WordPress using the source code below.</p>
<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code><?php
add_action('admin_menu', function(){
add_menu_page(
'admin menu title'
, 'Test Top Menu'
, 'manage_options'
, 'test_top_menu'
, 'test_menu_contents'
, 'dashicons-calendar'
,0
);
});
function test_menu_contents() {
// your HTML output code
}</code></pre></div>
<pre class="wp-block-code"><code>
</code></pre>
<h3 class="wp-block-heading" id="vk-htags-52d904d7-fa2e-4749-a6a3-5cc413a37a3d">Add top menu</h3>
<p>Add the function that adds the admin menu to the WordPress top menu to the action hook name <span data-color="#f78da7" style="background: linear-gradient(transparent 60%,rgba(247, 141, 167, 0.7) 0);" class="vk_highlighter"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-black-color"><strong><span class="marker-thickGray" style="color: #ff0000;">admin_menu</span></strong></mark></span> using <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-black-color"><span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter"><strong><span class="marker-thickGray" style="color: #ff0000;">add_action</span></strong></span></mark>().</p>
<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>add_action('admin_menu', function(){
// your code
});</code></pre></div>
<pre class="wp-block-code"><code>
</code></pre>
<p>Furthermore, implement the function to add an admin menu using <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-black-color"><span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter"><span class="marker-halfGray" style="color: #ff0000;"><strong>add_menu_page</strong></span></span></mark>().</p>
<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code>$hook = add_menu_page(
string $page_title,
string $menu_title,
string $capability,
string $menu_slug,
callable $function = '',
string $icon_url = '',
int $position = null
);</code></pre></div>
<pre class="wp-block-code"><code>
それでは<strong><span class="marker-halfGray" style="color: #ff0000;"><span data-color="#fcb900" style="background: linear-gradient(transparent 60%,rgba(252, 185, 0, 0.7) 0);" class="vk_highlighter"><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-black-color">add_menu_page</mark></span></span>()</strong>の引数をみてみましょう。
</code></pre>
<div class="wp-block-vk-blocks-border-box vk_borderBox vk_borderBox-background-transparent has-text-color has-vivid-cyan-blue-color is-style-vk_borderBox-style-solid-kado-tit-banner"><div class="vk_borderBox_title_container has-background has-vivid-cyan-blue-background-color"><i class=""></i><h4 class="vk_borderBox_title">add_menu_page()の引数</h4></div><div class="vk_borderBox_body">
<ul class="wp-block-list">
<li>$page_title (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">required</mark></strong>)<br>The text that appears in the page's title tag when the menu is selected.</li>
<li>$menu_title (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">required</mark></strong>)<br>Text used for the menu title.<br>In the sample in this article, "Test Top Menu" is displayed on the left side of the WordPress management console.</li>
<li>$capability (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">required</mark></strong>)<br>Permissions required to display this menu to users.<br>The sample in this article grants the managed_options permission, which allows access to the management menu.</li>
<li>$menu_slug (<strong><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color">required</mark></strong>)<br>Slug name to refer to this menu.<br>Must be unique for this menu page. Additionally, only lowercase alphanumeric characters, dashes, and underscore characters are allowed.</li>
<li>$function (optional)<br>Function called to output the content of this page.</li>
<li>$icon_url (optional)<br>URL to the icon used for this menu.<br>Pass the URL to the icon included in the plugin using the <a href="https://developer.wordpress.org/reference/functions/plugins_url/">plugins_url</a> function.<br>You can also use <a href="https://developer.wordpress.org/resource/dashicons/">Dashicons</a> font icons. The sample in this article uses the calendar icon dashicons-calendar.</li>
<li>$position (optional)<br>The position in the menu order in which this item appears.<br>By default it is at the bottom of the admin menu structure. In the sample of this article, it is specified and displayed at the top. Please refer to the following to determine where to place it in the menu structure.
<ul class="wp-block-list">
<li>2 – Dashboard</li>
<li>4 – Separator</li>
<li>5 – Post</li>
<li>10 – Media</li>
<li>15 – Link</li>
<li>20 – Page</li>
<li>25 – Comments</li>
<li>59 – Separator</li>
<li>60 – Appearance</li>
<li>65 – Plugins</li>
<li>70 – User</li>
<li>75 – Tools</li>
<li>80 – Settings</li>
<li>99 – Separator</li>
</ul>
</li>
<li>$hook_suffix (optional)<br>Prefix of the function that receives the processing results of the page displayed in this management menu.</li>
</ul>
</div></div>
<p>Implement a function to generate the page displayed in the top menu. In the sample in this article, only the title and a simple string are displayed.</p>
<div class="hcb_wrap"><pre class="prism line-numbers lang-php" data-lang="PHP"><code><?php
add_menu_page(
'admin menu title'
, 'Test Top Menu'
, 'manage_options'
, 'test_top_menu'
, 'test_menu_contents'
, plugins_url( 'myplugin/assets/icon.png')
,0
);
function test_menu_contents() {
?>
<div class="wrap">
<h1>Test Option Settings</h1>
<p>Hello admin menu !!</p>
</div>
<?php
}</code></pre></div>
<pre class="wp-block-code"><code>
</code></pre>
<h2 class="wp-block-heading" id="vk-htags-d3983128-cd7b-4079-b393-498f6f66e2bb">summary</h2>
<p><span style="font-size: 12pt;">This time, we introduced how to add an admin menu to the WordPress admin console. It requires implementation using PHP, but I think you'll find it easier than you expected.</span></p>
<p><span style="font-size: 12pt;">Since the management menu is a simple screen for site operators</span>, it is better to focus on functionality rather than design.</p>
<p>In Parts 2 to 4, we will introduce how to create submenus and management screens, how to update settings, etc., so please take a look.</p>
<div class="wp-block-vk-blocks-select-post-list vk_posts vk_posts-postType-post vk_posts-layout-media vk_postList"><div id="post-422" class="vk_post vk_post-postType-post media vk_post-col-xs-12 vk_post-col-sm-12 vk_post-col-md-6 vk_post-col-lg-6 vk_post-col-xl-6 vk_post-col-xxl-6 post-1786 post type-post status-publish format-standard has-post-thumbnail hentry category-wordpress category-blog-management tag-for-beginners tag-php tag-wordpress-management"><div class="vk_post_imgOuter media-img" style="background-image:url(https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-1024x683.jpg)"><a href="https://wakatchi.dev/en/adding-your-own-submenu-to-wordpress/"><img width="300" height="200" src="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-300x200.jpg" class="vk_post_imgOuter_img wp-post-image" alt="" srcset="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-300x200.jpg 300w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-600x400.jpg 600w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-1024x683.jpg 1024w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-768x512.jpg 768w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2-1536x1024.jpg 1536w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu2.jpg 1920w" sizes="(max-width: 300px) 100vw, 300px" /></a></div><!-- [ /.vk_post_imgOuter ] --><div class="vk_post_body media-body"><h5 class="vk_post_title media-title"><a href="https://wakatchi.dev/en/adding-your-own-submenu-to-wordpress/">WordPressに独自のサブメニューの追加する</a></h5><div class="vk_post_date media-date published">2023年10月20日</div></div><!-- [ /.media-body ] --></div><!-- [ /.media ] -->
<div id="post-563" class="vk_post vk_post-postType-post media vk_post-col-xs-12 vk_post-col-sm-12 vk_post-col-md-6 vk_post-col-lg-6 vk_post-col-xl-6 vk_post-col-xxl-6 post-1786 post type-post status-publish format-standard has-post-thumbnail hentry category-wordpress category-blog-management tag-for-beginners tag-php tag-wordpress-management"><div class="vk_post_imgOuter media-img" style="background-image:url(https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-1024x683.jpg)"><a href="https://wakatchi.dev/wordpress-admin-settings-api/"><img width="300" height="200" src="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-300x200.jpg" class="vk_post_imgOuter_img wp-post-image" alt="" srcset="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-300x200.jpg 300w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-600x400.jpg 600w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-1024x683.jpg 1024w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-768x512.jpg 768w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3-1536x1024.jpg 1536w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu3.jpg 1920w" sizes="(max-width: 300px) 100vw, 300px" /></a></div><!-- [ /.vk_post_imgOuter ] --><div class="vk_post_body media-body"><h5 class="vk_post_title media-title"><a href="https://wakatchi.dev/wordpress-admin-settings-api/">WordPressに値を設定する独自の管理メニューを追加する</a></h5><div class="vk_post_date media-date published">2023年10月25日</div></div><!-- [ /.media-body ] --></div><!-- [ /.media ] -->
<div id="post-565" class="vk_post vk_post-postType-post media vk_post-col-xs-12 vk_post-col-sm-12 vk_post-col-md-6 vk_post-col-lg-6 vk_post-col-xl-6 vk_post-col-xxl-6 post-1786 post type-post status-publish format-standard has-post-thumbnail hentry category-wordpress category-blog-management tag-for-beginners tag-php tag-wordpress-management"><div class="vk_post_imgOuter media-img" style="background-image:url(https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-1024x683.jpg)"><a href="https://wakatchi.dev/wordpress-admin-data-download/"><img width="300" height="200" src="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-300x200.jpg" class="vk_post_imgOuter_img wp-post-image" alt="" srcset="https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-300x200.jpg 300w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-600x400.jpg 600w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-1024x683.jpg 1024w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-768x512.jpg 768w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4-1536x1024.jpg 1536w, https://wakatchi.dev/wp-content/uploads/2023/10/wordpress-admin-menu4.jpg 1920w" sizes="(max-width: 300px) 100vw, 300px" /></a></div><!-- [ /.vk_post_imgOuter ] --><div class="vk_post_body media-body"><h5 class="vk_post_title media-title"><a href="https://wakatchi.dev/wordpress-admin-data-download/">WordPressにデータを取得する独自の管理メニューを追加する</a></h5><div class="vk_post_date media-date published">2023年10月27日</div></div><!-- [ /.media-body ] --></div><!-- [ /.media ] --></div>
<p><span style="font-size: 12pt;">The official website for WordPress developers introduces how to develop a management menu for the plugin handbook. Please refer to this article as well.</span></p>
<figure class="wp-block-embed is-type-wp-embed is-provider-wordpress-developer-resources wp-block-embed-wordpress-developer-resources"><div class="wp-block-embed__wrapper">
<div class="blog-card">
<div class="blog-card-body-outer">
<div class="blog-card-body">
<h5 class="blog-card-title">
<a href="https://developer.wordpress.org/plugins/administration-menus/">Administration Menus – Plugin Handbook | Developer.WordPress.org</a>
</h5>
<p class="blog-card-text">
Administration Menus are the interfaces displayed in WordPress Administration. They allow you to add option pages for your plugin. Top-Level… </p>
<div class="blog-card-site-title">
<a href="http://developer.wordpress.org">
<img loading="lazy" src="https://s.w.org/favicon.ico?2" width="16" height="16" alt="" >
WordPress Developer Resources </a>
</div>
</div>
</div>
<div class="blog-card-image-outer">
<a href="https://developer.wordpress.org/plugins/administration-menus/" class="blog-card-image-frame">
<img class="blog-card-image-src" src="https://developer.wordpress.org/wp-content/themes/wporg-developer-2023/images/opengraph-image.png" alt="">
</a>
</div>
</div>
</div></figure>
<p><span style="font-size: 12pt;">I hope this article is of some help.</span></p>
<p><span style="font-size: 12pt;">Thank you for reading to the end!</span></p>
Is there a way to save settings for a blog created with WordPress?
When running a site developed with WordPress, you may want to save the site's unique settings or change the settings while operating the site.
For site-specific settings, we recommend developing your own WordPress admin menu. Site setting values (parameters) can be changed by modifying the source code such as function.php using a plugin editor. However, if the source code is under version control or if the site operator is not good at coding, constant changes to the source code may not be healthy.
You can easily create an admin menu by simply calling functions provided by WordPress. Also, unlike the front-end screen that is open to site users, the management menu does not require much design, as a simple screen for site operators is sufficient.
In this article, we will show you how to add your own admin menu to WordPress.
This article is recommended for
WordPress site developers who want to configure the entire site from the WordPress admin screen
WordPress admin menus are coded in PHP using functions provided by WordPress. After a quick look, there aren't any plugins that allow you to flexibly configure the WordPress admin menu without any coding.
Using the admin menu is useful not only when developing WordPress themes and plugins, but also when developing a single site. As mentioned above, settings related to site operation can be written in source code, such as function.php, but it is not healthy to constantly change settings related to site behavior in source code. Source code and configuration values should be separated.
わかっち
The key to deciding whether to develop a management menu is who (developer? operator?) will be changing the site settings.
Add the admin menu to WordPress using add_menu_page(). Let's take a closer look here.
Add an admin menu to WordPress
The WordPress admin menu is the user interface displayed on the WordPress admin screen. You can add themes, plugins, and optional pages for your site.
The management menu has a top menu and submenus. Whether to use the top menu or a submenu is decided based on the characteristics of the plug-in and the needs of the user. Adding a top menu will give you your own top menu on the left side of the WordPress admin console. If you only add a submenu, the existing top menu will have its own submenu.
In this article, we will introduce a sample that adds a management menu called "Test Top Menu" to the WordPress management console and displays a screen called "Test Option Settings" as shown below.
Information
Here is a screenshot of the WordPress Dashboard (in Japanese). However, for multilingual purposes, the following Japanese text has been translated as follows:
管理メニュータイトル → admin menu title
テスト用トップメニュー → Test Top Menu
テスト用オプション設定 → Test Option Settings
The above screen can be incorporated into WordPress using the source code below.
<?php
add_action('admin_menu', function(){
add_menu_page(
'admin menu title'
, 'Test Top Menu'
, 'manage_options'
, 'test_top_menu'
, 'test_menu_contents'
, 'dashicons-calendar'
,0
);
});
function test_menu_contents() {
// your HTML output code
}
Add top menu
Add the function that adds the admin menu to the WordPress top menu to the action hook name admin_menu using add_action().
add_action('admin_menu', function(){
// your code
});
Furthermore, implement the function to add an admin menu using add_menu_page().
$page_title (required) The text that appears in the page's title tag when the menu is selected.
$menu_title (required) Text used for the menu title. In the sample in this article, "Test Top Menu" is displayed on the left side of the WordPress management console.
$capability (required) Permissions required to display this menu to users. The sample in this article grants the managed_options permission, which allows access to the management menu.
$menu_slug (required) Slug name to refer to this menu. Must be unique for this menu page. Additionally, only lowercase alphanumeric characters, dashes, and underscore characters are allowed.
$function (optional) Function called to output the content of this page.
$icon_url (optional) URL to the icon used for this menu. Pass the URL to the icon included in the plugin using the plugins_url function. You can also use Dashicons font icons. The sample in this article uses the calendar icon dashicons-calendar.
$position (optional) The position in the menu order in which this item appears. By default it is at the bottom of the admin menu structure. In the sample of this article, it is specified and displayed at the top. Please refer to the following to determine where to place it in the menu structure.
2 – Dashboard
4 – Separator
5 – Post
10 – Media
15 – Link
20 – Page
25 – Comments
59 – Separator
60 – Appearance
65 – Plugins
70 – User
75 – Tools
80 – Settings
99 – Separator
$hook_suffix (optional) Prefix of the function that receives the processing results of the page displayed in this management menu.
Implement a function to generate the page displayed in the top menu. In the sample in this article, only the title and a simple string are displayed.
<?php
add_menu_page(
'admin menu title'
, 'Test Top Menu'
, 'manage_options'
, 'test_top_menu'
, 'test_menu_contents'
, plugins_url( 'myplugin/assets/icon.png')
,0
);
function test_menu_contents() {
?>
<div class="wrap">
<h1>Test Option Settings</h1>
<p>Hello admin menu !!</p>
</div>
<?php
}
summary
This time, we introduced how to add an admin menu to the WordPress admin console. It requires implementation using PHP, but I think you'll find it easier than you expected.
Since the management menu is a simple screen for site operators, it is better to focus on functionality rather than design.
In Parts 2 to 4, we will introduce how to create submenus and management screens, how to update settings, etc., so please take a look.
The official website for WordPress developers introduces how to develop a management menu for the plugin handbook. Please refer to this article as well.