Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

As far as I know the showing and hiding of the admin toolbar on the front-end is a global setting, which applies to any page containing wp_footer().

I want to have more specific control over the visibility admin bar—specifically, to be able to hide it based on a URL query string, such as (e.g., ?hidetoolbar at the end of a URL).

I know that I can hide the toolbar from a specific template file by adding this to the top:

     add_filter('show_admin_bar', '__return_false');

What hook would I use to apply the filter conditionally in functions.php?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You should be able to just add the filter inside of a conditional:

<?php if ($_GET['hidetoolbar']) 
{
    add_filter('show_admin_bar', '__return_false');
}
?>

or, since conditionally adding action handlers and filters is sometimes frowned upon, you could add your own function as a filter and then put your conditional inside that:

<?php 
function my_manage_toolbar()
{
    if ($_GET['hidetoolbar']) 
    {
        return false;
    }
    return true;
}
add_filter('show_admin_bar', 'my_manage_toolbar');
?>
share|improve this answer
add comment

You can try this in your functions.php file :

if (isset($_GET['hidetoolbar'])) {
    add_filter('show_admin_bar', '__return_false');
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.