Instead of disabling the WordPress 3.1 Admin Bar, use this plugin, based on Codrops Fixed Fade Out Menu, to fade away the WordPress Admin Bar when you scroll down the page. The plugin is availeable in the WordPress Plugin Directory
Changelog:
- 1.0.1 - Thanks to @TheFrosty, added is_admin_bar_showing()
- 1.0.0 - initial release
Source:
<br />
<?php<br />
/*<br />
Plugin Name: PerS Fade Away WordPress Admin Bar<br />
Plugin URI: https://soderlind.no/archives/2011/02/25/fade-away-wordpress-admin-bar/<br />
Description: Fade away the WordPress Admin Bar when you scroll down the page.<br />
Version: 1.0.1<br />
Author: PerS<br />
Author URI: https://soderlind.no<br />
*/</p>
<p>/*<br />
Change log:<br />
1.0.1 - Thanks to @TheFrosty, added is_admin_bar_showing()<br />
1.0.0 - initial release<br />
*/</p>
<p>if (!class_exists('ps_pers_fade_wp_admin_bar')) {<br />
class ps_pers_fade_wp_admin_bar {<br />
var $url = '';<br />
function __construct(){<br />
$this->url = plugins_url(basename(__FILE__), __FILE__);<br />
add_action('wp_print_scripts', array(&$this,'ps_pers_fade_wp_admin_bar_script'));<br />
}<br />
function ps_pers_fade_wp_admin_bar_script() {<br />
if (is_admin_bar_showing()) {<br />
wp_enqueue_script('jQuery('); // other scripts included with Wordpress: https://tinyurl.com/y875age<br />
wp_enqueue_script('ps_pers_fade_wp_admin_bar_script', $this->url.'?ps_pers_fade_wp_admin_bar_javascript'); // embed javascript, see end of this file<br />
}<br />
}<br />
} //End Class<br />
} //End if class exists statement</p>
<p>if (isset($_GET['ps_pers_fade_wp_admin_bar_javascript'])) {<br />
//embed javascript<br />
Header("content-type: application/x-javascript");<br />
echo<<<ENDJS<br />
/**<br />
* @desc PerS Fade Away WP Admin Bar<br />
* @author PerS - https://soderlind.no<br />
*/<br />
// Script from https://tympanus.net/codrops/2009/12/11/fixed-fade-out-menu-a-css-and-jquery-tutorial/<br />
jQuery(document).ready(function(){<br />
jQuery(window).scroll(function(){<br />
var scrollTop = jQuery(window).scrollTop();<br />
if(scrollTop != 0)<br />
jQuery('#wpadminbar').stop().animate({'opacity':'0.2'},400);<br />
else<br />
jQuery('#wpadminbar').stop().animate({'opacity':'1'},400);<br />
});</p>
<p> jQuery('#wpadminbar').hover(<br />
function (e) {<br />
var scrollTop = jQuery(window).scrollTop();<br />
if(scrollTop != 0){<br />
jQuery('#wpadminbar').stop().animate({'opacity':'1'},400);<br />
}<br />
},<br />
function (e) {<br />
var scrollTop = jQuery(window).scrollTop();<br />
if(scrollTop != 0){<br />
jQuery('#wpadminbar').stop().animate({'opacity':'0.2'},400);<br />
}<br />
}<br />
);<br />
});</p>
<p>ENDJS;</p>
<p>} else {<br />
if (class_exists('ps_pers_fade_wp_admin_bar')) {<br />
$ps_pers_fade_wp_admin_bar_var = new ps_pers_fade_wp_admin_bar();<br />
}<br />
}<br />
?><br />