简体   繁体   English

自定义帖子类型的WordPress sub_menu_page

[英]Wordpress sub_menu_page on custom post type

I would love to add a sub menu page on my custom post type called "vouchercodes", but everytime I click on this item in the menu I get "Sorry, you are not allowed to access this page." 我希望在自定义帖子类型上添加一个名为“ vouchercodes”的子菜单页面,但是每次我在菜单中单击此项目时,都会显示“对不起,您不能访问此页面”。

I found some articels that "should" work: 我发现一些应该“起作用”的关节:
https://developer.wordpress.org/reference/functions/add_submenu_page/ https://wordpress.stackexchange.com/questions/63202/how-to-add-a-sub-menu-page-to-a-custom-post-type https://developer.wordpress.org/reference/functions/add_submenu_page/ https://wordpress.stackexchange.com/questions/63202/how-to-add-a-sub-menu-page-to-a-custom-后期类型

But none of those worked for me. 但是这些都不对我有用。 I'm sure that I use an full administrator account and I haven't recived any error's in my error logs. 我确定我使用了完整的管理员帐户,并且没有在错误日志中发现任何错误。

The code I use: 我使用的代码:

function sens_admin_add_submenus(){
    add_submenu_page('edit.php?post_type=vouchercodes', 'Custom Settings', 'Settings', 'manage_options', 'vouchercodes_settings', 'My_Custom_Callback');
}
add_action('admin_init', 'sens_admin_add_submenus');

And my simpel callback function: 还有我的simpel回调函数:

function My_Custom_Callback(){
    echo "<h1>Welcome to my awsome setting's page</h1>";
}

What am I doing wrong? 我究竟做错了什么?


Answer Fix from ishio : ishio的 答案修复:

Change admin_init to admin_menu admin_init更改为admin_menu

将add_action调用从admin_init更改为admin_menu将纠正此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM