Skip to content

Project gallery with tabs in WordPress

Projects sorted by type of work, arranged in tabs that work with the keyboard and screen readers.

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

galerie-onglets-projets.php
<?php
/**
 * Plugin Name: Forge, Galerie de réalisations par onglets
 * Description: Des réalisations classées par type de chantier, rangées dans des onglets accessibles au clavier et aux lecteurs d’écran. Ajoute la composition « Galerie de réalisations par onglets » à 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-galerie-onglets-projets
 *
pattern.html
<!-- wp:html -->
<section class="gop" data-gop aria-labelledby="gop-titre">
        <p class="gop-eyebrow">Rénovation Martin · Haute-Savoie</p>
        <h2 class="gop-title" id="gop-titre">Nos réalisations par type de chantier</h2>
        <div class="gop-tabs" role="tablist" aria-label="Types de chantier">
          <button class="gop-tab" type="button" role="tab" id="gop-tab-cuisines" aria-controls="gop-panel-cuisines" aria-selected="true" tabindex="0" data-gop-tab>Cuisines <span class="gop-badge">3</span></button>
          <button class="gop-tab" type="button" role="tab" id="gop-tab-bains" aria-controls="gop-panel-bains" aria-selected="false" tabindex="-1" data-gop-tab>Salles de bain <span class="gop-badge">3</span></button>
          <button class="gop-tab" type="button" role="tab" id="gop-tab-extensions" aria-controls="gop-panel-extensions" aria-selected="false" tabindex="-1" data-gop-tab>Extensions <span class="gop-badge">3</span></button>
        </div>
        <div class="gop-panel" role="tabpanel" id="gop-panel-cuisines" aria-labelledby="gop-tab-cuisines" tabindex="0" data-gop-panel>
          <ul class="gop-grid" role="list">
            <li class="gop-card">
script.js
(() => {
  if (!document.querySelector(".gop")) return;
  document.querySelectorAll("[data-gop]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const tabs = Array.from(root.querySelectorAll("[data-gop-tab]"));
    const panels = Array.from(root.querySelectorAll("[data-gop-panel]"));

    const select = (index, focus) => {
      tabs.forEach((tab, i) => {
        tab.setAttribute("aria-selected", String(i === index));
        tab.tabIndex = i === index ? 0 : -1;
        panels[i].hidden = i !== index;
style.css
:root {
  --gop-card: #ffffff;
  --gop-text: #1b2420;
  --gop-muted: #4e5b55;
  --gop-line: #d7e0db;
  --gop-accent: #166a52;
  --gop-on-accent: #ffffff;
  --gop-soft: #e3f1ec;
  --demo-galerie-onglets-projets-bg: #e9efec;
  --demo-galerie-onglets-projets-text: #1b2420;
}

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

Galleries and carousels components in WordPress
  • A product photo that zooms in under the pointer, and from the keyboard with Enter and the arrow keys, to inspect the details.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Building site photos sorted by dated step on a vertical timeline, with the current step highlighted.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • YouTube videos shown as thumbnails: the player only loads on click, to respect privacy and keep the page light.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A slideshow that fills the whole screen, browsed with the keyboard or a finger swipe, and closed with Escape.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component