If you manage websites for your team or your clients, or are the head developer of your business, you may want to make WordPress customizations that only you can see, or hide buttons for all users other than you to be sure people don’t click where they shouldn’t .
While you can customize admin tools using a plugin like Branda, you can also do this easily using code.
For this example, let’s say that you are the only superadmin of a site and want to hide the toolbar for every user except yourself.
Just create a mu-plugin and add the following code and style it using CSS:
<?php
add_action( ‘admin_footer’, ‘hideitems’ );
function hideitems() {
if ( ! is_super_admin() ) {
echo «<style>
#wpadminbar {
display: none !important;
}
</style> «;
}
}
2. Hide WordPress Top Menu And Create A Custom Logout Button
Here’s another WordPress admin customization you can do for your clients.
Let’s say you want to hide or remove the top bar on your client sites’ admin areas because you find it’s inconvenient to have it display there or feel that giving clients who don’t know much about WordPress access to content modification menus could lead to them making inadvertent mistakes.
For example, if you build sites using Elementor, your clients can access Elementor’s theme customization options directly from the top menu bar.
Users can add a new Elementor template in their WordPress toolbar.
Sticking with Elementor for this example, you may decide to hide this to avoid problems and leave the theme customization path inside the admin area at Templates > Theme Builder. Or you may decide to remove it altogether, because even if you disable options from the admin bar, some users may still not understand what it is and why it displays on the front end of their sites.
Hiding the top bar is very easy to do using a plugin like Branda…just go to Admin area > Admin bar and then uncheck the toolbar visibility for some users.
The problem is, if you completely disable this bar, users won’t be able to logout from their admin. This not only creates a security issue, it’s also not convenient if you want to switch users.
Fortunately, there is a solution: Simply add this code as a mu-plugin to create a logout button:
<?php
add_action(
‘admin_menu’,
function () {
add_menu_page(
‘Logout’,
‘Logout’,
‘read’,
‘wp_custom_logout_menu’,
‘__return_false’,
‘dashicons-marker’,
1 // Here use 1 for placing menu on top or PHP_MAX_INT to place it at the bottom,
);
}
);
add_action(
‘admin_init’,
function () {
if ( isset( $_GET[‘page’] ) && $_GET[‘page’] == ‘wp_custom_logout_menu’ ) {
wp_redirect( wp_logout_url() );
exit();
}
}
);
This will redirect your user to the login page after the logout process.
3. Add CSS To WordPress Backend
How can you add CSS to the WordPress backend?
Once again, you can use a plugin like Branda, but you could also create an mu-plugin and paste the following code in your file:
<?php
add_action( ‘admin_footer’, ‘my_admin_css’ );
function my_admin_css() {
echo ‘<style>
/*Put your CSS code here*/
</style>’;
}
That’s it…easy and very handy!
4. Remove All Styles From WordPress Content
Suppose you come across a site where all the content style is set by HTML within the WordPress content.
This is kind of a bummer, since no one really wants to modify the style of each page when you can easily do this using CSS.
So, here’s a workaround for this.
Create a mu-plugin, and add the following code:
add_filter(
‘the_content’,
function ( $content ) {
// Delete all inline style.
return preg_replace( ‘/ style=(«|’)(.*?)(«|’)/’, », $content );
}
);
Try it out!
5. Hide Elementor In WordPress Admin
Elementor is one of the popular and widely-used page builders for WordPress. If you are a web developer or webmaster, you may be using Elementor to create and manage a website and its content.
As easy as Elementor is, it still requires some knowledge to use it and an inadvertent mistake by a user could make the site impossible to navigate.
So, if you are the only one managing the website and users don’t need to create pages in WordPress very often, you might want to hide Elementor options from other backend users. Making sure there is no modification happening to the backend without your knowledge will give you peace of mind and your customers or backend users may also appreciate having a simpler interface to work with.
This tip works well on the following kinds of sites:
eCommerce sites
Websites with custom posts types
Websites used mainly as a blog to publish articles.
As stated earlier, if end users need to regularly create WordPress pages, this might not work for you because they will need Elementor for this.
Before creating an mu-plugin, first you must hide Elementor in the menu. You can then hide the Elementor button on WordPress pages.
1. Hide Elementor in the menu
Install Branda and then:
Go to Admin area > Admin bar and hide it for your end users. This way they will not be able to access the Elementor builder from there.
Go to Dashboard > Admin menu > Customize and then hide the Elementor admin menu for everyone except you (tip: use user roles for this as it is easier than doing it for every user).
Remember to also hide the “Templates” menu (this is probably the most critical thing to hide).
Note: We recommend that only one person should be able to access the templates, especially if using these to build your theme and using CSS to control every item of your site’s design. This prevents other users from adding CSS elsewhere (e.g. in builders, theme customizer, stylesheets, etc.)…and without commenting properly when adding code, e.g.
/* Header customization */
.header{
margin-top: 10px;
}
/* END Header customization */
2. Hide the Elementor button on WordPress pages
The easiest way to create or modify a page with Elementor is simply to go to Pages > Create and click on the Elementor button to change it.
There is also a way to hide this button if you do not want users to access Elementor at all.
To do this, you need to customize user roles. If you are the only admin of the site, you can hide the buttons for everyone except you.
Note: You can use the previous step to hide the Elementor templates only (to keep your theme safe) but still leave access in Elementor to create and modify pages. This, however, can be risky, since when users are on an Elementor page, they can navigate to other elements like the header or footer, or access Elementor global settings that will affect the site.
Once you have done the above, the only thing left to do is create a mu-plugin and paste the following code to hide the button :
<?php
add_action( ‘admin_footer’, ‘hideitems’ );
function hideitems() {
if ( ! is_super_admin() ) {
?>
<style>
#elementor-switch-mode {
display: none;
}
</style>
<?php
}
}
Enjoy!
6. Make Beehive Analytics Your WordPress Dashboard Home Page
If you are not a huge fan of the WordPress admin page (even if you can customize its widgets and hide panels) or having your users see this screen every time they log into their WordPress dashboard…
Look but don’t look…is this what you want users to see when they log in?
Why not show them a beautiful admin landing page with useful information like this?
Oooh…aaah…charts and stats…that’s much better!
Again, you can use Branda to customize the admin panel and the left menu or hide/show menus depending on the user role. This is great if you are the only admin and want to display the minimum required menus for end users or add custom CSS.
If, however, all you want to do is redirect users from the WordPress admin page to a more useful page like the Beehive analytics page, then simply create an mu-plugin and add this code:
<?php
function wpmudev_redirect_page() {
global $pagenow;
if ( $pagenow == ‘index.php’ && ! wp_doing_ajax() && is_plugin_active( ‘google-analytics-async/google-analytics-async.php’ ) ) {
wp_redirect( admin_url( ‘/admin.php?page=beehive-google-analytics’ ) );
exit;
}
}
add_action( ‘admin_init’, ‘wpmudev_redirect_page’ );
Enjoy!
Make WordPress Fly With MU-Plugins
Hopefully, now you know all about Must-Use plugins: what they are, when and when not to use them, and how and where to install them on WordPress sites.
Check out our mu-plugins documentation, try creating and installing some must-have plugins of your own, and if you experience any issues or need expert help, contact our support team…we’re available 24/7 to answer any WordPress questions you have!
Contributors
This article was written in collaboration with:
Antoine – Incensy. I am passionate by web culture and digital solutions. I have been working in this area for 11 years now. Always looking for the best solutions to help my customers overcome digital challenges and grow their business online. My vision of digital success: Get a global strategy, apply it with detailed precision, and always keep improving.
***
Note: We do not accept articles from external sources. WPMU DEV members, however, may contribute ideas and suggestions for tutorials and articles on our blog via the Blog XChange.