How to Show WordPress Toolbar When Viewing Your Site

Home » Snippets » How to Show WordPress Toolbar When Viewing Your Site
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

As a WordPress user, you may have noticed that the toolbar disappears when you’re looking at your site. This can be inconvenient if you need quick access to your dashboard, or if you want to edit a post on the fly. Fortunately, there’s a simple way to show the toolbar when viewing your site. In this article, we’ll show you how to keep the toolbar visible at all times.

					function wpturbo_show_toolbar_on_front_end() {
    if ( is_admin_bar_showing() ) {
        return true;
    } else {
        return false;
    }
}
add_filter( 'show_admin_bar', 'wpturbo_show_toolbar_on_front_end' );
				

The code snippet above is used to display WordPress toolbar when viewing the front end of the website. By default, the toolbar is hidden when you are viewing the website from the front end.

To achieve this functionality, we create a new function called wpturbo_show_toolbar_on_front_end(). This function checks if the Admin Bar is currently showing by using the is_admin_bar_showing() function. If it is showing, the function returns true. If it is not showing, the function returns false.

if ( is_admin_bar_showing() ) {
    return true;
} else {
    return false;
}

Next, we use the add_filter() function to attach the wpturbo_show_toolbar_on_front_end() function to the show_admin_bar filter. The show_admin_bar filter is responsible for determining whether or not the WordPress toolbar should be displayed on the front-end of the website.

add_filter( 'show_admin_bar', 'wpturbo_show_toolbar_on_front_end' );

When this filter is applied, it will call the wpturbo_show_toolbar_on_front_end() function and use its return value (true or false) to decide whether or not to display the toolbar on the front-end of the website.

By using this code snippet, you can show the WordPress toolbar when viewing the front end of your website, making it easier to navigate or edit your content while you’re browsing your site.

Register an account to save your snippets or go Pro to get more features.