How to Hide WordPress Menus in Admin Panel

WordPress is a powerful content management system that comes with super features. If you are professionally preparing websites for your customers, some of your curious customers may mess up wordPress features, try to edit the theme files, corrupting or changing to settings or codes required for the site to work properly. In order to avoid such situations, you need to hide some menus in the admin panel. So now I will show you how you can hide these menus in the admin panel.

Why Do We Need to Hide Menus in Admin Panel

Theme files and plugin files can be edited as standards on the WordPress admin panel. When we log into WordPress’ admin panel, it gives you the opportunity to edit your theme file by clicking on the theme editor at the bottom of the view and clicking the I Understand button. If you wish you can also edit other theme files from here. In other words, you can somehow edit theme files and theme codes. This also means that customers with the right to login to the admin panel can edit the theme files. In other words, they have the right to consciously or unconsciously edit these codes and make changes on the theme files. In the same way, we have the opportunity to edit the plugins by clicking on the I Understand button again by coming to the plugin editor option under the plugins.

Now, when we sent the admin panel to the customer with the login information, the customer can edit these parts, but we don’t want it to be this way. We don’t want customers to be able to make any edits. We can prevent this. From here, we can hide the plugin editor and the theme editor tabs and pages under Appearance.

Disable Theme Editor and Plugin Editor

In order to do this, I enter the functions.php in the theme file. I’m writing this code in a suitable part of the page.

define( 'DISALLOW_FILE_EDIT', true );

This code makes it impossible to edit files through the admin panel. I save this file. I go back to the admin panel. Let’s pretend we are back in. Under Appearance, as you can see, the theme editor is gone. And under Plugins the plugin editor is gone. In this case, I can say that there is a restriction to edit through this admin panel in any way. The importance of this is that if your customers don’t understand the codes and try to edit these codes or ask someone else they think they know, this site may become unusable. Our aim is to prevent this. Of course, the theme editor alone is not enough. Here we use plugins. Some of us use custom themes. There are settings here, intended to disrupt the content of the site. Imagine your customers come here, on this page, just to enter a blog post.

Hide Menus / Pages in Admin Panel

Obviously, most of the clients you are building a website for want to use WordPress very simply. Because blogger just come here to post a post. Only the Posts tab should appear. I would say that seeing these pages, all other pages, is unnecessary for them.

Not showing all the other unnecessary pages both provides the customer with a much simpler panel and does not prevent the site from working correctly as it doesn’t tamper with the settings. We also need functions.php to hide these tabs and pages in the admin panel. Let’s open that page again. On this page, we can write under the theme editor section. We can write anywhere else. The function we need to write for this is. First of all, let’s assign a function and give it a name. It can be any name. Let’s write Remove Menus, then open and close the parenthesis.

Now we will open square brackets again and write the pages we want to hide in between. Then on the bottom line, you know, to run a function in functions.php, we need to add an Add Action to it. I write, Add Action. This function we created will work in the admin menu. This is standard, and here I am writing the name of Remove Menu that we just wrote. So I’m typing the name of the function. I’m ending this line with a semicolon. This is our function.

function remove_menus() {
  remove_menu_page( 'index.php' );                  //Dashboard
  remove_menu_page( 'edit.php' );                   //Posts
  remove_menu_page( 'upload.php' );                 //Media
  remove_menu_page( 'edit.php?post_type=page' );    //Pages
  remove_menu_page( 'edit-comments.php' );          //Comments
  remove_menu_page( 'themes.php' );                 //Appearance
  remove_menu_page( 'plugins.php' );                //Plugins
  remove_menu_page( 'users.php' );                  //Users
  remove_menu_page( 'tools.php' );                  //Tools
  remove_menu_page( 'options-general.php' );        //Settings
}
add_action( 'admin_menu', 'remove_menus' );

Disable Comments and Pages Menus in Admin Panel

Now let’s add the lines that will hide it. First of all, let’s hide the comment section here and the pages section. Then we will do the others, respectively. We will write the words we need to use in the function. We open our Remove Menu page parenthesis, and we mentioned the pages in quotation marks. First there is the page. I write edit.php post type page and at the end I put a semicolon. Let me duplicate this line. Because then we’ll have to hide the comments. These are standard again, it will hide the pages. I think these will also hide the comments. I save and go to the admin panel again and refresh the page. Look, both the pages and comments here are hidden. This is our basic method.

However, it should not be forgotten that the fact that these pages are private doesn’t mean that they can’t be accessed. It just hides from the left side menu. If the URLs of these pages are already unknown, customers who don’t understand these jobs will not be able to access these pages. But do not forget that it is possible to enter these pages directly with the URL. Now I’m coming to the post section, let’s start and hide the posts. So here is what we understand. Remove Menu Page is our basic hide function.

Hide Dashboard / Index Page in Admin Panel

Each line we write here, refers to each option in the admin panel. Dashboard is the part that appears when we enter the admin panel. We hide this and I will hide blog posts under it. I also use edit.php to hide blog posts. Now let’s save it and look again.

As you can see, there is no dashboard and no Posts. I want to Posts section because my client enters their content through this tab. That’s why I put two slashes at the beginning of this line of Posts, so that this part appears as a comment. This part will not be considered. When I save and look again, I can see the Posts appear here.

Hide Media, Appearance, Plugins, Users, Tools and Settings Menus in WP Admin Panel

Let’s remove the others one by one. First we will hide the default options of WordPress. Portfolio is a custom post type we created. I will show you how to hide it. I will show you how to hide the plugins we have added as well. Contact is also an option that the plug-in called Contact Form 7 brings here. We will come to them too. So does ACF’s custom field tab. After the Posts, there is the Media section. Let’s hide the Media. We use upload.php for this. Let’s hide Appearance, Plugins, Users, Tools and Settings on the left. We write themes.php to hide the Appearance. plugins.php to hide Plugins. users.php to hide users, tools.php to hide tools and options-general.php to hide settings. Let’s save the file.

Hide Contact Form 7 Plugin Menu

As you can see all of WordPress’ standard options are gone. We left the post for the client ourselves. We will pass to the others now. when you add a plugin in WordPress, various options may appear on the left. Contact being one of them. An option that Contact Form 7 grades. I come to contact. They don’t have standards. That’s why we need to examine it. When you come to contact, you will see a word like this in the address bar. We will use this word. I’m copying this word and this time I’m typing the word I copied between quotation marks. This is the word I can use to hide Contact Form 7. I’m saving this file and when I look again, I see that page is not here.

remove_menu_page( 'wpcf7' );   //Contact Form

Hide Custom Fields Menu in Admin Panel

Now let’s talk onto the custom fields. The word for Custom Fields is that, I’ll try that first. Let’s see if there will be a solution. I’m saving and refreshing. There was no solution. Because what we need to do in these special fields is to save it with edit.php. If you remember, we said that edit.php should hide those whose post type is page. What we need to do here is similar, edit.php post type this time. We need to hide ACF. I press Ctrl + S and this time when I look at the page, I can see that the custom fields are also disappearing from here. By applying these two methods, you can hide the options added here that are not in your control.

Disable Custom Post Type Menus

Now, let me show you how we can hide the custom post types we created. I click on it again. I’m looking at the URL structure again. In the URL structure, I see the familiar edit.php again, I’m copying it completely like this, starting from the edit.php part and writing it on a new line. I save it Ctrl + S. I refresh the page and I see that the custom post type I created is also hidden from the left side. This is how the custom post types are hidden.

Remove Menus by User Roles in Admin Panel

There is one more thing I want to show you. Changes we can make to users. So I can be admin and see all the options on the left. But let’s say I don’t want to show an editor all the tabs on the left. And also, if we assigned the client as an editor, I might want to client only Posts to appear. We can adjust them depending on the user’s roles. For example, I’m an administrator. We will need to add something to the Add Action section in the functions.php file right away.

if(current_user_can( 'editor' )){
   add_action( 'admin_menu', 'remove_menus' );
}

The current user will control whatever it is and apply these functions accordingly. I’m writing my code right above Add Action. If current user can. I open the parenthesis again. Let’s say if it is an editor, I open the square brackets. I close the square bracket below. That’s the meaning. If the logged in user is the editor, apply all these edits to him or her. I press Ctrl + S and check.

I am not an editor. I am logged in as an administrator, since I am an administrator. I see all the options on the left. But if I wanted it to be applied specifically to administrators, if I wanted it to be applied according to administrators, then I would write administrator here instead of the editor. And when I save and refresh the page, all the applications and all lines here were applied to me because I’m an administrator. In this way, it is possible for your customers or other users to hide them, hide tabs, hide pages, through the roles you set. This ensures that a user logging into the admin panel doesn’t see more options than they can use. This is a feature that I think will be useful for those who make a website with WordPress.

Popular Tutorials

5 Best Free Must Have SEO Plugins for WordPress in 2022 (No Yoast)

WordPress is one of the most popular site-building and content management systems…

How to Find WordPress Admin Panel Login Link?

You’ve just installed WordPress and you’re excited to start building your site….

What is the Difference Between WordPress Posts and Pages?
What is the Difference Between WordPress Posts and Pages?

If you’re just getting started with WordPress, you might be wondering what…

Activating WordPress Maintenance Mode with WP-CLI

In this tutorial, I’ll show you how to activate WordPress Maintenance Mode…

XAMPP Installation and Usage | Running PHP Codes on Localhost
XAMPP Installation and Usage | Running PHP Codes on Localhost

In this video, I’ll explain what needs to be done for your…

How to Hide WordPress Menus in Admin Panel
How to Hide WordPress Menus in Admin Panel

WordPress is a powerful content management system that comes with super features….