Hide Any Plugin from the WordPress Dashboard

Last modified Sep 10, 2020
Difficulty Advanced
Language CSS, PHP
Category

There are cases where you don’t want people to know what plugin you used to build your (or your client’s) website. Here is a WordPress code snippet which will hide any plugin from the WordPress Dashboard. You need to add the following code in functions.php file of your active WordPress Theme and find CSS selectors of the plugin you want to hide and replace it from the snippet.

Useful links

✅ Related post: Should I Rebrand and White Label Divi for Clients? 
✅ Related post: How to Use Your Browser’s Developer Tools
✅ Divi Ghoster –  This Divi plugin removes all traces of the Divi or Extra theme from the front end, back end, and source code of your website. Custom brand your website in seconds.
✅ Transforming Divi with CSS & JQuery – Divi Course, learn the art of CSS and jQuery.

 

In this example, we will hide WP and Divi Icons Pro plugin and WP Layouts plugin, because they are appearing in different places. WP Layouts has its own, top-level tab when WP and Divi Icons Pro is displayed as a sub-menu of the Divi tab.

1. Hide the Top-level Element from the Admin Menu

The first thing we need to do is define the ID of the menu item that we would like to remove. The easiest way to get the ID is to inspect the source code using your browser. Here is a screenshot of the list elements in the admin menu:

To hide the WP Layouts Tab, this is the code you can use:

#adminmenu li#toplevel_page_ags-layouts  {display:none;}

Selectors: #adminmenu (to select the menu section) and li#toplevel_page_ags-layouts ( to select the tab, replace with the plugin id you want to hide) and property display:none; (to hide it)

 

2. Hide the Sub-menu Element from the Admin Menu

If you want to hide the sub-menu element, follow these instructions. Select the right parent tab as we did in the previous step. As you can see, submenu items don’t have any unique class or ID we can correspond to. We will do a trick with :nth-of-type(number) CSS selector, so we can select every <li> element that is the nth element of its parent.

Notice, that Divi is the first of the element!

 

#adminmenu li#toplevel_page_et_divi_options li:nth-of-type(8)  {display:none;}

 

 

3. Hide Element from Top Navigation

Steps are the same, just find the right selectors!

#wpadminbar #wp-admin-bar-new-content-default li#wp-admin-bar-new-project {display:none;}

 

4. Hide the Plugin From the Plugin Page

Go to the plugin page, use the inspect element and select the plugin you want to hide. Find in the code “data-slug” attribute and replace it in the code below.

 

.plugins-php .plugins tr[data-slug="wp-and-divi-icons-pro"]{ display:none; }

 

5. Paste the Code to the PHP Function

To execute the code in the WordPress area, we need to use WordPress ‘admin_head’ hook below. Past the code to the functions.php of the active theme.

add_action('admin_head', 'my_custom_css_do');

function my_custom_css_do() {
echo '<style>


/* YOUR CODE HERE */


</style>';

 

Is there a way to hide plugin only for specific role/roles?

Yes, you can! Let us know in the comments if you want us to create a snippet how to do that 😉

PHP

add_action('admin_head', 'my_custom_css_do'); 

function my_custom_css_do() { 
echo '<style> 

#adminmenu li#toplevel_page_ags-layouts {display:none;} 
#adminmenu li#toplevel_page_et_divi_options li:nth-of-type(8) {display:none;} 
#wpadminbar #wp-admin-bar-new-content-default li#wp-admin-bar-new-project {display:none;} 
.plugins-php .plugins tr[data-slug="wp-and-divi-icons-pro"]{ display:none; } 

</style>'; 
}

 

Does this snippet (still) work?

Please let us know in the comments if everything worked as expected. We have tested this code with the Version: 4.0.1 of the Divi Theme and Divi Friendly Hosting with PHP 7.3 and WordPress 5.2.4. The code is not tested with WordPress Multisite.  If this code saved you time, we want to hear about it in the comments! ?

____

License: This snippet contains code from https://codex.wordpress.org, copyright WordPress.org, modified by Divi Space, October 23, 2019. Licensed under the GNU General Public License, no warranty; click here for details.

Your Comments

3 Comments

  1. Christian

    should be easy with:

    function my_custom_css_do() {

    if (is_user_logged_in()) {
    $user = wp_get_current_user();
    $roles = (array)$user->roles;

    $allowed_roles = [
    ‘editor’,
    ‘administrator’,
    ‘author’
    ]; // or whatever roles you need

    if (array_intersect($allowed_roles, $roles)) {
    echo ‘
    #adminmenu li#toplevel_page_ags-layouts {display:none;}
    #adminmenu li#toplevel_page_et_divi_options li:nth-of-type(8) {display:none;}
    #wpadminbar #wp-admin-bar-new-content-default li#wp-admin-bar-new-project {display:none;}
    .plugins-php .plugins tr[data-slug=”wp-and-divi-icons-pro”]{ display:none; }
    ‘;
    }
    }
    }

    Sorry, I couldn’t format here ….

    Reply
  2. Melle Lefferts

    Is there a way to hide for all roles except for admin (= me).

    Reply
  3. Jules Webb

    RE: Is there a way to hide plugin only for specific role/roles?

    It would be useful to set up a conditional if user id not-equal-to my-id then hide …..

    Can you show an example of that?

    Thanks!
    Jules

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Receive notifications about our new blog posts.