Adding custom admin bar menu item

0
22

Sometimes we need to have a custom admin bar menu item to be added so that we can have an ease of access to a specific page.

I have come up with a simple and efficient solution for that. Here I am assuming if you need a shortcut to WP Super Cache page where you can easily clear the cache.

We will check whether user is already admin

if(!is_super_admin() || !is_admin_bar_showing()) return;

Check if WP Super Cache plugin is active

if ( is_plugin_active( 'wp-super-cache/wp-cache.php' ) ) {

You can always replace the 'wp-super-cache/wp-cache.php' with any plugin for which you would like to check if plugin exist, if your menu is not based on any plugin you can remove the else condition.

If you simply would like to have menu added without any dependency on the plugin you can use:

This will simply add the admin bar menu entry with the title ‘My Custom link’.

Do not forget to add this code to your themes functions.php file.

LEAVE A REPLY

Please enter your comment!
Please enter your name here