I am trying to hide WordPress admin bar from all pages except the home page.

I added the following CODE in the theme’s functions.php file, but it hides the admin bar on all pages:

if ( ! is_single() ) {
   add_filter( 'show_admin_bar', '__return_false' );
}

I want it to appear only on the homepage and to be hidden everywhere else.

4 Answers
4

You should use conditional tag inside function hooked to show_admin_bar filter.

add_filter( 'show_admin_bar', 'show_adminbar_on_homepage_only', 20 );
function show_adminbar_on_homepage_only()
{
     return is_user_logged_in() && is_front_page();
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *