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.

I'm just trying to turn off the wp admin bar on one page, but this function removes it from every page. What am I missing?

<?php 
  if ( !is_page('image-upload') ):
    show_admin_bar(false);
  endif;
?>
share|improve this question
    
Try this tutorial. –  Rohit Pande Jan 10 '13 at 10:45
    
Where are you inserting this code? –  brasofilo Jan 10 '13 at 10:54
    
In my functions.php –  Pam Jan 10 '13 at 10:57
2  
Please, research before asking, there are plenty of examples. :::: Also, the PHP manual is your friend, the Codex too. –  brasofilo Jan 10 '13 at 11:03
add comment

3 Answers

up vote 1 down vote accepted

You need to remove the (!) infront of the conditional, you can read about PHP-operators here.

Now you simply say that if not on page "image-upload" remove the admin_bar.. Here is the working code:

<?php 
function wpse_80018_hide_admin_bar() {
   // If is on page "image-upload"
   // Remove the admin_bar
   if ( is_page('image-upload') ):
      show_admin_bar(false);
   endif;
}
add_action('wp_head', 'wpse_80018_hide_admin_bar');
?>

Just an example to understand the conditional:

<?php
function wpse_80018_test() {
    // If iam on page "image-upload"
    // Echo honey i'm home!
    // If on another page echo "Working on another page!"
    if ( is_page('image-upload') ) {
       echo "Honey i'm home!";
    } else {
       echo "Working on another page!";
    }
}
add_action('wp_head', 'wpse_80018_test');
?>
share|improve this answer
    
That's not working either. It shows on every page, including the 'image-upload' page. –  Pam Jan 10 '13 at 10:49
    
It's not working because of this: [Function_Reference/is_page]This tag must be used BEFORE The Loop. Encapsule this inside a wp_head action hook and it works. –  brasofilo Jan 10 '13 at 11:12
    
Ofcourse this need to be in a action. Thanks for pointing that out @brasofilo –  Pontus Abrahamsson Jan 10 '13 at 11:35
    
Thanks for your help! It's working now. –  Pam Jan 10 '13 at 12:07
    
Hey, your welcome! If this worked for you, please accept the answer if you can @Pam –  Pontus Abrahamsson Jan 10 '13 at 13:35
add comment

Hide Admin Bar for everyone

This one is reasonably simple, to hide the WordPress Admin Bar for everyone, add the following to your theme’s functions.php file, the first bit hides the admin bar, the second bit hides the settings:

add_filter( 'show_admin_bar', '__return_false' );

function wp_hide_admin_bar_settings() {
    ?>
    <style type="text/css">
        .show-admin-bar {
            display: none;
        }
    </style>
    <?php
}

function wp_hide_admin_bar() {
    add_filter( 'show_admin_bar', '__return_false' );
    add_action( 'admin_print_scripts-profile.php', 
         'wp_hide_admin_bar_settings' );
}
add_action( 'init', 'wp_hide_admin_bar' , 9 );

Hide WordPress Admin Bar for specific requests

if ( isset($_GET['bar']) && 'no' == $_GET['bar'] )
   add_filter( 'show_admin_bar', '__return_false' );

This would allow you to hide the WordPress admin bar by going to example.com/?bar=no, you can of course change those values.


To hide the WP Admin Bar and the Admin Bar preference on his/her profile page for a specific user, add the following to your theme's functions.php file:

function wp_hide_admin_bar_settings() {
    ?>
    <style type="text/css">
        .show-admin-bar {
            display: none;
        }
    </style>
    <?php
}

function wp_hide_admin_bar() {
   if ( 2 == get_current_user_id() ) {
      add_filter( 'show_admin_bar', '__return_false' );
      add_action( 'admin_print_scripts-profile.php', 'wp_hide_admin_bar_settings' );
   }
}
add_action( 'init', 'wp_hide_admin_bar' , 9 );

Or you could do the reverse, and enable the WordPress Admin Bar just for one user, by disabling it for everyone else:

function wp_hide_admin_bar_settings() {
    ?>
    <style type="text/css">
        .show-admin-bar {
            display: none;
        }
    </style>
    <?php
}

function wp_hide_admin_bar() {
   if ( 2 != get_current_user_id() ) {
      add_filter( 'show_admin_bar', '__return_false' );
      add_action( 'admin_print_scripts-profile.php', 
          'wp_hide_admin_bar_settings' );
   }
}
add_action( 'init', 'wp_hide_admin_bar' , 9 );
share|improve this answer
    
+1 for the nice alternatives. ::: Your Answer is not showing properly, take a look at the formatting guide. ::: Tip: when you find a nice formated question or answer, click edit, check the markdown and click cancel right after, taking good care of not clicking Save Edits. ::: Doubt: don't the CSS solution leave a blank space? –  brasofilo Jan 10 '13 at 11:41
    
Selva, the formatting was really broken, I've revised it. Please, confirm that it is all ok. When you are editing, there is a preview where you can check how it looks. For blocks of code, simply paste it, select all and use the { } button in the editing toolbar. –  brasofilo Jan 10 '13 at 12:48
    
Thanks brasofilo –  Selva Balaji Jan 10 '13 at 12:59
add comment

It should be <?php if ( is_page('image-upload') ): show_admin_bar(false); endif; ?>

remove '!' from !is_page

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.