![](https://i-blog.csdnimg.cn/blog_migrate/ed2fc5494d38b6f29f89010ddc762175.png)
宝塔面板wordpress
Have you ever worked with a client who has a hard time understanding technology? Well, as a consultant, designer, or developer, it is your job to make things easier for them. WordPress admin panel comes with a lot of options in the menu, but you can get rid of them fairly easily if necessary. With one of our clients, we needed to get rid of few menu items, so it is easier for her to understand things. In this article, we will show you how easy it is to remove a menu item in the WordPress Admin Panel.
您是否曾与难以理解技术的客户一起工作? 好吧,作为顾问,设计师或开发人员,使他们的事情变得简单是您的工作。 WordPress管理面板在菜单中带有很多选项,但是如果有必要,您可以轻松地摆脱它们。 与我们的一位客户一起,我们需要摆脱一些菜单项,因此她更容易理解事物。 在本文中,我们将向您展示在WordPress管理面板中删除菜单项有多么容易。
For WordPress 3.1 or above, just paste the following code in your theme’s functions.php file:
对于WordPress 3.1或更高版本,只需将以下代码粘贴到主题的functions.php文件中:
add_action( 'admin_menu', 'my_remove_menu_pages' );
function my_remove_menu_pages() {
remove_menu_page('link-manager.php');
}
In version prior to WordPress 3.1, you would need to paste the following code in your theme’s functions.php file:
在WordPress 3.1之前的版本中,您需要将以下代码粘贴到主题的functions.php文件中:
function remove_menus () {
global $menu;
$restricted = array(__('Links'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
add_action('admin_menu', 'remove_menus');
The code above will get rid of the Links option for all users (including administrators). Only two user roles are allowed to see the Link tab (Administrators and Editors). Now if this is for a multi-author site (where there are many editors), and you as an administrator still want access to the Links menu, then you can add parameters to do so.
上面的代码将为所有用户(包括管理员)删除“链接”选项。 仅允许两个用户角色查看“链接”选项卡(管理员和编辑者)。 现在,如果这是用于多作者站点(其中有许多编辑器),并且您作为管理员仍希望访问“链接”菜单,则可以添加参数来这样做。
You would need to utilize the function current_user_can(), and with a simple if statement, you can get rid of the link menu or other items for specific user role.
您将需要使用函数current_user_can() ,并使用简单的if语句,就可以摆脱链接菜单或其他针对特定用户角色的项目。
This is a very handy trick for consultants and developers who work on larger sites.
对于在大型网站上工作的顾问和开发人员来说,这是一个非常方便的技巧。
Additional Sources
其他来源
Remove Menu PageCurrent User Can Function ReferenceUser Roles and Capabilities Chart
翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-remove-menu-item-in-wordpress-admin-panel/
宝塔面板wordpress