我已经从管理侧栏中删除了post菜单,如下所示:
add_action(\'admin_menu\',\'remove_default_post_type\');
function remove_default_post_type() {
remove_menu_page(\'edit.php\');
}
现在如何将其从顶部栏的“新建”菜单中删除?我已经从管理侧栏中删除了post菜单,如下所示:
add_action(\'admin_menu\',\'remove_default_post_type\');
function remove_default_post_type() {
remove_menu_page(\'edit.php\');
}
现在如何将其从顶部栏的“新建”菜单中删除?如果URL已知,用户仍然可以创建新帖子,如domain.com/wp-admin/post-new.php
这是你可以使用的代码。。。已将其添加到文件中functions.php
function hide_add_new() {
global $submenu;
// For Removing New Posts from Admin Menu
unset($submenu[\'post-new.php?post_type=post\'][10]);
// For Removing New Pages
unset($submenu[\'post-new.php?post_type=page\'][10]);
// For Removing CPTs
unset($submenu[\'post-new.php?post_type=custom_post_type\'][10]);
}
add_action(\'admin_menu\', \'hide_add_new\');
//Thanks to Howdy_McGee
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'new-post\');
$wp_admin_bar->remove_menu(\'new-page\');
$wp_admin_bar->remove_menu(\'new-cpt\');
}
add_action( \'wp_before_admin_bar_render\', \'remove_admin_bar_links\' );
function disable_new_post() {
if ( get_current_screen()->post_type == \'my_post_type\' )
wp_die( "You ain\'t allowed to do that!" );
}
add_action( \'load-post-new.php\', \'disable_new_post\' );
要删除子菜单,您可以检查您将看到的菜单li
将具有类似的IDwp-admin-bar-new-content
要删除所述菜单项,只需删除wp-admin-bar-
. 这样我们就可以看到+New -> Post
ID为的项目wp-admin-bar-new-post
所以我们可以这样删除它:
function remove_admin_bar_links() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu(\'new-post\');
}
add_action( \'wp_before_admin_bar_render\', \'remove_admin_bar_links\' );
请尝试使用以下代码:
add_action( \'admin_bar_menu\', \'wpse126922_remove_newpost\', 999 );
function wpse126922_remove_newpost ( $wp_admin_bar ) {
$wp_admin_bar->remove_node( \'new-post\' );
}
遵循列出的教程here, 很抱歉,数据没有保存到我试图设置的用户元中。这个过程本身似乎很简单,但元数据没有被保存。在运行jQuery脚本时,我没有遇到任何控制台错误和运行的小成功动画。<?php add_action( \'admin_footer\', \'ring_jquery\' ); function ring_jquery() { ?> <script type=\"text/javascript\">