WordPress函数:add_theme_page 在后台侧边栏-外观,添加子菜单

追格官方小助手/ 2022年06月29日/ WordPress/ 浏览 954

add_theme_page 函数 在Wordpress后台侧边栏的【外观】下添加子菜单。


函数 add_pages_page 在内部调用的是 函数 add_submenu_page


函数源码:


function add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $callback = '', $position = null ) {
    return add_submenu_page( 'themes.php', $page_title, $menu_title, $capability, $menu_slug, $callback, $position );
}


可以看到,add_pages_page 比 add_submenu_page 就是固定了第一个参数,传入了:‘themes.php’。


使用举例:


function add_test_theme_page() {
    add_theme_page( 'Theme Title Settings', 'Theme Menu Settings', 'edit_theme_options', 'test-theme-options', 'theme_option_page' );
}
add_action( 'admin_menu', 'add_test_theme_page' );
 
function theme_option_page() {
    echo 'This is a test theme options page!';
}


发表评论

暂无评论,抢个沙发...

客服 工单