• 欢迎来到本站,本站主要做程序员相关技术、博客、笔记,如果喜欢本网站那么赶紧使用Ctrl+D 收藏吧!
  • 如果有任何疑问,可以在下方文章下方留下你的评论~

WordPress remove and customize Admin menu

视频教程 8个月前 (10-23) 4次浏览 0个评论

When you log in to WordPress admin, there are different administration menus on the left side of the screen. You may need to delete/hide some management menus in some cases. Today we will share the implementation methods.

WordPress remove and customize Admin menu

For example, suppose you have a plugin that adds its settings menu to the administration menu. But we really don’t want or need a menu item because it only takes up valuable screen space. Therefore, remove the item from the menu.

Remove WordPress administration menu with code

First of all, let’s prepare according to the following new steps:

  1. Click on the menu link
  2. Copy the web address of the page from the browser’s address bar

Example

Add the following code to the functions.php:

function wpdaxue_remove_menu_item() {
    remove_menu_page('menu-slug');
}
add_action('admin_menu', 'wpdaxue_remove_menu_item', 999);

Next, replace the menu slug in the code with the menu item you want to remove. For example, if your page address looks like this:

https://example.com/wp-admin/edit.php?post_type=simple-pay

Then, you willedit.php?post_type = simple-payis used as a menu item.

Therefore, the final code is:

function wpdaxue_remove_menu_item() {
    remove_menu_page('edit.php?post_type=simple-pay');
}
add_action('admin_menu', 'wpdaxue_remove_menu_item', 999);

Save the changes and finish.

Remove non administrator menu items

From the perspective of security, sometimes it is necessary to block some management menus for non administrators.

Example

function wpdaxue_remove_menu_item() {
    if (!current_user_can('manage_options')) {
        remove_menu_page('edit.php?post_type=simple-pay');
    }
}
add_action('admin_menu', 'wpdaxue_remove_menu_item', 999);

Here, we use the current_user_can() function to check whether the current user is an administrator. If the user is not an administrator user, the menu item will be removed.

Using the plugin to remove WordPress admin menu

If you don’t know how to juggle code, or if you need to be more flexible in setting up multiple menu items, consider trying the Admin Menu Editor,Hide Admin Menu ,Remove admin menus by roles or Adminimize.


中国笔友, 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:WordPress remove and customize Admin menu
喜欢 (0)
发表我的评论
取消评论
表情 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址