Skip to content

Dismissible announcement bar in WordPress

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.

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

bandeau-annonce-fermable-memorise.php
<?php
/**
 * Plugin Name: Forge, Bandeau d'annonce fermable
 * Description: Un bandeau fin en haut de page avec message, lien et bouton de fermeture ; une fois fermé, il ne réapparaît plus pendant la durée choisie. Ajoute la composition « Bandeau d'annonce fermable » à 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-bandeau-annonce-fermable-memorise
 *
pattern.html
<!-- wp:html -->
<div class="bafm" id="bafm-conges-fin-annee" role="region" aria-label="Annonce" data-bafm data-bafm-id="conges-fin-annee" data-bafm-days="30">
        <div class="bafm__inner">
          <svg class="bafm__icon" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3.5" y="5" width="17" height="15.5" rx="2"/><path d="M3.5 10h17M8 3v4M16 3v4M8 14h2M14 14h2M8 17h2"/></svg>
          <p class="bafm__text"><strong>Congés de fin d’année :</strong> l’atelier ferme du 24 décembre au 4 janvier. Les commandes passées avant le 15 décembre sont livrées avant Noël. <a class="bafm__link" href="#horaires">Voir les horaires</a></p>
          <button class="bafm__close" type="button" aria-label="Fermer l’annonce" data-bafm-close hidden><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 6l12 12M18 6 6 18"/></svg></button>
        </div>
      </div>
<!-- /wp:html -->
script.js
(() => {
  if (!document.querySelector(".bafm")) return;
  document.querySelectorAll("[data-bafm]").forEach((bar) => {
    const id = bar.dataset.bafmId || "annonce";
    const key = `forge-annonce:${id}`;
    const days = Number(bar.dataset.bafmDays) || 0;
    const until = bar.dataset.bafmUntil;
    const close = bar.querySelector("[data-bafm-close]");
    // Restore buttons usually come later in the page than this script: look them up on each render.
    const restores = () => document.querySelectorAll(`[data-bafm-restore="${id}"]`);
    // After the end date (last day included) the bar disappears on its own, without any storage.
    const expired = Boolean(until) && Date.now() > new Date(`${until}T23:59:59`).getTime();
style.css
:root {
  --bafm-bg: #1f2a44;
  --bafm-text: #ffffff;
  --bafm-line: #1f2a44;
  --bafm-accent: #ffd48a;
  --bafm-hover: rgb(255 255 255 / 0.15);
  --bafm-page-muted: #57534e;
  --bafm-action: #1f2a44;
  --demo-bandeau-annonce-fermable-memorise-bg: #f6f3ee;
  --demo-bandeau-annonce-fermable-memorise-text: #1c1917;
}

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 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
  • Quick access links that appear on the first Tab press to skip the header and menu, as required by the RGAA and WCAG.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component