Skip to content

Full-screen hamburger mobile menu in WordPress

A hamburger button that morphs into a cross and opens a full-screen menu: trapped focus, Escape to close and a call button at the bottom.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

menu-mobile-hamburger-plein-ecran.php
<?php
/**
 * Plugin Name: Forge, Menu mobile hamburger plein écran
 * Description: Un bouton hamburger qui se transforme en croix et ouvre un menu plein écran : focus piégé, fermeture à Échap et bouton d’appel en bas. Ajoute la composition « Menu mobile hamburger plein écran » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-menu-mobile-hamburger-plein-ecran
 *
pattern.html
<!-- wp:html -->
<header class="mmhp" data-mmhp>
        <div class="mmhp__bar">
          <a class="mmhp__brand" href="#accueil"><span class="mmhp__mark" aria-hidden="true">AV</span>Atelier Verdier</a>
          <button type="button" class="mmhp__toggle" aria-expanded="false" aria-controls="mmhp-menu" data-mmhp-toggle hidden>
            <span class="mmhp__icon" aria-hidden="true"><span class="mmhp__line mmhp__line--1"></span><span class="mmhp__line mmhp__line--2"></span><span class="mmhp__line mmhp__line--3"></span></span>
            Menu
          </button>
        </div>
        <div class="mmhp__panel" id="mmhp-menu" data-mmhp-panel>
          <nav aria-label="Navigation principale">
            <ul class="mmhp__list">
script.js
(() => {
  if (!document.querySelector(".mmhp")) return;
  document.querySelectorAll("[data-mmhp]").forEach((root) => {
    const toggle = root.querySelector("[data-mmhp-toggle]");
    const panel = root.querySelector("[data-mmhp-panel]");
    let blocked = [];

    // Everything outside the toggle and the panel becomes inert, so screen readers stay in the menu too.
    function isolate() {
      const path = new Set();
      [toggle, panel].forEach((el) => {
        for (let node = el; node && node !== document.body; node = node.parentElement) path.add(node);
style.css
:root {
  --mmhp-bg: #fffaf3;
  --mmhp-text: #2a1e14;
  --mmhp-muted: #6b5747;
  --mmhp-line: #eadfd2;
  --mmhp-hover: #f5ebde;
  --mmhp-card: #ffffff;
  --mmhp-accent: #9a3412;
  --mmhp-accent-hover: #7c2d12;
  --mmhp-on-accent: #ffffff;
  --mmhp-mark: #2a1e14;
  --mmhp-on-mark: #fffaf3;

Free component: copy it freely, including for commercial projects.

Breadcrumbs and pagination components in WordPress
  • A bottom bar with Call, Directions and Free quote that tucks away while visitors read down the page and returns as soon as they scroll up. Built for tradespeople whose customers arrive on a phone.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A slim bar at the top of the page with a message, a link and a close button; once closed, it stays hidden for the period you choose.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A sticky sidebar table of contents for blog posts: it highlights the section being read, shows the reading time left and folds into a list under the title on mobile.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A column of dots on the side of the page that follows the section being read and lets visitors jump to it, with a label on hover and focus.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An order step indicator: finished steps clickable to go back, the current step announced, upcoming steps locked.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Tooltips in four positions that open on hover, tap and keyboard focus, and close with Escape, as WCAG requires.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component