4 techniques needed to improve WordPress's menu bar

If you have just upgraded WordPress to version 3.1, it will discover a new point that the system will display the WordPress Admin bar for administrators and normal users to log in. If WP Admin Bar was created to provide users with convenience ...

QuanTriMang - If you have just upgraded WordPress to version 3.1, it will discover a new point that the system will display WordPress Admin bar for administrators and normal users to log in . If WP Admin Bar was created to provide users with convenience via the links on the top of each page, then this function does not come with any form of customization, has inadvertently affected somewhat that is its usefulness. In the following article, we will introduce 4 basic ways to improve the utility of WP Admin Bar.

1. Remove the links available from WP Admin Bar:

Go to the theme folder, and open the functions.php file with the application to edit any text. Then, add the following code to the end:

add_action ('wp_before_admin_bar_render', 'remove_admin_bar_links');
function remove_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> remove_menu ('comments');
}

The above code will remove the COMMENTS link from the Admin Bar . The operation mechanism is based on the function $ wp_admin_bar-> remove_menu (ID) , by providing the ID of the path to be deleted (in this case the corresponding ID is COMMENTS ), you can completely remove any path from the Admin Bar.

Below is a list of some frequently used IDs and very useful for most of us:

- my-account-with-avatar / my-account: connecting to your account, here the ID parameter depends on whether the user is active or not to display the avatar.

- my-blogs: Sites menu, only works with Network mode.

- edit: link to edit posts or pages.

- new-content: add New menu.

- comments: connect to comments.

- appearance: Appearance menu.

- updates: update the path.

- get-shortlink: create a short path to any page.

2. Assign a custom path to WP Admin Bar:

To add your own links to the Admin bar menu, add the following lines of code in the functions.php file:

add_action ('wp_before_admin_bar_render', 'add_admin_bar_links');
function add_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> add_menu (array (
'id' => 'Google',
'title' => __ ('Google'),
'href' => 'http://google.com'
));
}

According to the above example, we have added Google.com as a new path in Admin Bar, of course it can be adjusted to anything according to your requirements. The parameters to note here are id, title and href:
id: identification point of the path.
title: The name displayed on the Admin Bar.
href: the path address will point to.

For example, you can create submenu using the following code:

add_action ('wp_before_admin_bar_render', 'add_admin_bar_links');
function add_admin_bar_links () {
global $ wp_admin_bar;
$ wp_admin_bar-> add_menu (array (
'id' => 'Google',
'title' => __ ('Google'),
'href' => 'http://google.com'
));
$ wp_admin_bar-> add_menu (array (
'parent' => 'Google',
'id' => 'GoogleAnalytics',
'title' => __ ('Google Analytics'),
'href' => 'http://google.com/analytics'
));
}

The result will look like the image below:

Picture 1 of 4 techniques needed to improve WordPress's menu bar

3. Display the login form if the user is not logged in:

By default, the Admin Bar bar is only available for logged-in users. But for some reason, if you want this Admin Bar to always be displayed, and come with login templates if the user is not logged in, use WordPress Admin Bar Improved to enable this feature.

4. Turn off completely Admin Bar:

It sounds unreasonable, but many people want to completely remove this menu bar. Log in to the main WordPress panel and select the Profile tab. Under Show Admin Bar , uncheck chech at when viewing site and print dashboard:

Picture 2 of 4 techniques needed to improve WordPress's menu bar

If you are a multi-blog manager (or work in Network mode) and want to turn off the Admin Bar for all authors, add the following line of code in the functions.php file :

add_filter ('show_admin_bar', '__return_false');

Good luck!

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile