WordPress.org

Make WordPress Core

#21746 closed defect (bug) (invalid)

show_admin_bar(false) still adds CSS and JS

Reported by: ahmednuaman Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Toolbar Keywords:
Focuses: Cc:

Description

I'd expect show_admin_bar(false) to totally hide the admin toolbar. Instead it leaves fragments in the app, for example in the header it still adds:

<link rel='stylesheet' id='admin-bar-css'  href='/wp-includes/css/admin-bar.css' type='text/css' media='all' />
<style type="text/css" media="print">#wpadminbar { display:none; }</style>
<style type="text/css" media="screen">
	html { margin-top: 28px !important; }
	* html body { margin-top: 28px !important; }
</style>

And in the footer:

<script type='text/javascript' src='/wp-includes/js/admin-bar.js'></script>

Change History (9)

comment:1 SergeyBiryukov20 months ago

  • Component changed from Template to Toolbar
  • Keywords reporter-feedback added

Could not reproduce. My guess is that you're calling show_admin_bar( false ); too late.

Both _wp_admin_bar_init() and wp_admin_bar_render() return early and don't include any styles or scripts if the toolbar is properly disabled.

Have you tried disabling all plugins and switching to the default theme (Twenty Eleven)?

Related/duplicate: #16249

comment:2 follow-up: ahmednuaman20 months ago

When should I call it? I've currently got it at the top of my header.php file, well before WP's header and footer functions.

comment:3 in reply to: ↑ 2 SergeyBiryukov20 months ago

Replying to ahmednuaman:

When should I call it?

In theme's functions.php file:
http://codex.wordpress.org/Function_Reference/show_admin_bar#Notes

comment:4 ahmednuaman20 months ago

But I want it to appear within the admin, I don't want it to appear for certain users on the front end, so I followed: http://codex.wordpress.org/Function_Reference/show_admin_bar#Examples

comment:5 SergeyBiryukov20 months ago

  • Keywords reporter-feedback removed

It will still appear in the admin, since it's a persistent part of the navigation since 3.3 (#17899, #18197, #19685, #19766).

comment:6 SergeyBiryukov20 months ago

Updated the Codex page. It suggested calling show_admin_bar() in template files before wp_footer(), which is wrong.

It should be called immediately upon plugin load, so functions.php is the appropriate place:
http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/admin-bar.php#L700

comment:7 ahmednuaman20 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Ok cool, I'll amend the code. Thanks.

comment:8 SergeyBiryukov20 months ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:9 SergeyBiryukov20 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from reopened to closed
Note: See TracTickets for help on using tickets.