將子選單頁面作為工具的子頁面新增到導航欄

add_action('admin_menu', 'register_my_custom_submenu_page');
 
function register_my_custom_submenu_page() {
    add_submenu_page(
        'tools.php',
        'Submenu Page',
        'My Custom Submenu Page',
        'manage_options',
        'my-custom-submenu-page',
        'my_custom_submenu_page_content' );
}
 
function my_custom_submenu_page_content() {
    echo '<div class="wrap">';
        echo '<h2>Page Title</h2>';
    echo '</div>';
}

輸出

StackOverflow 文件

說明

在程式碼中,我們建立了一個名為 register_my_custom_submenu_page 的函式,我們使用 add_submenu_page 將專案作為 tools.php 的子項新增到導航欄,這是 tools 頁面。

請檢查此頁面中的引數部分以瞭解我們傳入的引數。然後我們使用 add_action 來執行我們的 register_my_custom_submenu_page 函式。最後,我們建立了函式 my_custom_submenu_page_content 來顯示頁面中的內容。