Skip to content

Toolbar: Add access+w keyboard shortcut to toggle toolbar on frontend#11456

Open
apermo wants to merge 4 commits intoWordPress:trunkfrom
apermo:feature/toolbar-toggle-shortcut
Open

Toolbar: Add access+w keyboard shortcut to toggle toolbar on frontend#11456
apermo wants to merge 4 commits intoWordPress:trunkfrom
apermo:feature/toolbar-toggle-shortcut

Conversation

@apermo
Copy link
Copy Markdown

@apermo apermo commented Apr 7, 2026

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

  • Toggle only: Hide the toolbar; press again to bring it back.
  • No persistence: Resets on page navigation — designed for quick previews.
  • Frontend only: Does not work in wp-admin (toolbar is not optional there, see #19685).
  • Smooth animation: 200ms CSS transition (slide up/down).
  • Page spacing adjusts: Sets --wp-admin--admin-bar--height: 0px when hidden, so scroll-padding-top and bump margin-top adjust automatically.
  • Accessible: aria-live region announces state changes; aria-hidden set on the toolbar element.

Changes

  1. src/js/_enqueues/lib/admin-bar.jskeydown listener for Ctrl+Shift+F, toggleToolbar() function, screen reader announcements.
  2. src/wp-includes/css/admin-bar.csshtml.wp-toolbar-hidden rules: CSS variable reset, margin override, transform: translateY(-100%) + visibility: hidden.
  3. src/wp-includes/class-wp-admin-bar.phpwp_localize_script for screen reader strings.

Shortcut rationale

Ctrl+Shift+F was chosen after evaluating and discarding several alternatives:

  • access+w (Ctrl+Option+W / Alt+Shift+W): Initial choice. Discarded because Ctrl+Option on macOS conflicts with the accessibility Display zoom modifier, and Alt+Shift on Windows switches keyboard input language on multi-language setups.
  • Ctrl+Shift+H: "H for Hide" — discarded because Firefox uses Ctrl+Shift+H for 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 require Alt+Shift+7).

Ctrl+Shift+F is free across all major browsers (Chrome, Firefox, Safari, Edge) on all platforms, works on every keyboard layout, and follows the ctrlShift modifier 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:

  • Research: Auditing existing WordPress keyboard shortcuts, browser shortcut conflicts, and Trac history for prior proposals.
  • Implementation: Writing the JavaScript toggle logic, CSS hidden state rules, and PHP localization. All code was reviewed and directed by the human author.
  • Trac ticket draft: The ticket description was drafted by AI and reviewed by the human author.

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.

apermo added 2 commits April 7, 2026 00:33
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.
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props apermo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

apermo and others added 2 commits April 7, 2026 10:18
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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ! important need here?

Copy link
Copy Markdown
Author

@apermo apermo Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

function wp_enqueue_admin_bar_bump_styles() {
if ( current_theme_supports( 'admin-bar' ) ) {
$admin_bar_args = get_theme_support( 'admin-bar' );
$header_callback = $admin_bar_args[0]['callback'];
}
if ( empty( $header_callback ) ) {
$header_callback = '_admin_bar_bump_cb';
}
if ( '_admin_bar_bump_cb' !== $header_callback ) {
return;
}
// Back-compat for plugins that disable functionality by unhooking this action.
if ( ! has_action( 'wp_head', $header_callback ) ) {
return;
}
remove_action( 'wp_head', $header_callback );
$css = '
@media screen { html { margin-top: 32px !important; } }
@media screen and ( max-width: 782px ) { html { margin-top: 46px !important; } }
';
wp_add_inline_style( 'admin-bar', $css );
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants