Toolbar: Add access+w keyboard shortcut to toggle toolbar on frontend#11456
Toolbar: Add access+w keyboard shortcut to toggle toolbar on frontend#11456apermo wants to merge 4 commits intoWordPress:trunkfrom
Conversation
Add access+w (Alt+Shift+W / Ctrl+Option+W) keyboard shortcut to temporarily hide/show the toolbar on the frontend. Slides the bar out with a CSS transition and adjusts page spacing via the --wp-admin--admin-bar--height custom property. Includes screen reader announcements for accessibility. Frontend only — the toolbar remains fixed in wp-admin per existing core policy.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replace access+w (Ctrl+Option+W / Alt+Shift+W) with Ctrl+Shift+F. Unified across all platforms, no per-OS modifier branching needed.
| */ | ||
| html.wp-toolbar-hidden { | ||
| --wp-admin--admin-bar--height: 0px; | ||
| margin-top: 0 !important; |
There was a problem hiding this comment.
Why ! important need here?
There was a problem hiding this comment.
The admin bar "bump" styles — which push the page content down to make room for the toolbar — are added as inline CSS via wp_enqueue_admin_bar_bump_styles() in admin-bar.php
wordpress-develop/src/wp-includes/admin-bar.php
Lines 1285 to 1310 in 074792e
That rule uses !important.
Our override:
html.wp-toolbar-hidden { margin-top: 0 !important; }needs !important too, otherwise the bump style's !important would always win regardless of our higher specificity (html.wp-toolbar-hidden > html). With both using !important, our selector wins because it's more specific — which is exactly what we want.
Add a keyboard shortcut (
Ctrl+Shift+F) to temporarily hide and show the toolbar on the frontend. This gives logged-in users a quick way to preview their site without the toolbar, without navigating to Profile settings or logging out.Shortcut:
Ctrl+Shift+F(all platforms)Behavior
--wp-admin--admin-bar--height: 0pxwhen hidden, soscroll-padding-topand bumpmargin-topadjust automatically.aria-liveregion announces state changes;aria-hiddenset on the toolbar element.Changes
src/js/_enqueues/lib/admin-bar.js—keydownlistener forCtrl+Shift+F,toggleToolbar()function, screen reader announcements.src/wp-includes/css/admin-bar.css—html.wp-toolbar-hiddenrules: CSS variable reset, margin override,transform: translateY(-100%)+visibility: hidden.src/wp-includes/class-wp-admin-bar.php—wp_localize_scriptfor screen reader strings.Shortcut rationale
Ctrl+Shift+Fwas chosen after evaluating and discarding several alternatives:access+w(Ctrl+Option+W / Alt+Shift+W): Initial choice. Discarded becauseCtrl+Optionon macOS conflicts with the accessibility Display zoom modifier, andAlt+Shifton Windows switches keyboard input language on multi-language setups.Ctrl+Shift+H: "H for Hide" — discarded because Firefox usesCtrl+Shift+Hfor the History sidebar.primaryShift+\(Cmd+Shift+\ / Ctrl+Shift+): Matches Gutenberg's distraction-free mode shortcut. Discarded because\is not directly accessible on non-US keyboard layouts (e.g. German keyboards requireAlt+Shift+7).Ctrl+Shift+Fis free across all major browsers (Chrome, Firefox, Safari, Edge) on all platforms, works on every keyboard layout, and follows thectrlShiftmodifier pattern already used in WordPress for region navigation. "F" is mnemonic for "Frontend view."Prior Art
This PR is based on the keyboard toggle feature from Apermo AdminBar (GitHub) by @apermo. The toggle is also available as a standalone lightweight version: Apermo AdminBar Toggle. The human author of this PR is the plugin author.
Trac ticket: https://core.trac.wordpress.org/ticket/65029
Use of AI Tools
This PR was authored collaboratively with Claude Code (Anthropic Claude Opus 4.6). The AI was used for:
The human author (@apermo) is also the author of the Apermo AdminBar / Apermo AdminBar Toggle plugins that this PR is based on. All code has been reviewed and the human author takes full responsibility for the contents of this PR.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.