Skip to content

Project gallery with lightbox in WordPress

A tradesperson's portfolio: a grid of jobs filtered by type of work, with place, year and duration, and a full-screen lightbox with captions and keyboard navigation.

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-realisations-grille.php
<?php
/**
 * Plugin Name: Forge, Galerie de réalisations avec visionneuse
 * Description: Le portfolio d'un artisan : une grille de chantiers filtrée par type de travaux, avec lieu, année et durée, et une visionneuse plein écran avec légendes et navigation au clavier. Ajoute la composition « Galerie de réalisations avec visionneuse » à 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-realisations-grille
 *
pattern.html
<!-- wp:html -->
<section class="rgal" aria-labelledby="rgal-title" data-rgal>
        <div class="rgal__head">
          <div>
            <h2 id="rgal-title">Nos réalisations</h2>
            <p class="rgal__intro">Quelques chantiers menés ces trois dernières années autour de Lyon. Touchez une photo pour l'agrandir.</p>
          </div>
          <div class="rgal__filters" role="group" aria-label="Filtrer par type de chantier" data-rgal-filters hidden>
            <button type="button" class="rgal__filter" data-rgal-filter="all" aria-pressed="true">Tous les chantiers</button>
            <button type="button" class="rgal__filter" data-rgal-filter="salle-de-bain" aria-pressed="false">Salle de bain</button>
            <button type="button" class="rgal__filter" data-rgal-filter="cuisine" aria-pressed="false">Cuisine</button>
            <button type="button" class="rgal__filter" data-rgal-filter="exterieur" aria-pressed="false">Extérieur</button>
script.js
(() => {
  if (!document.querySelector(".rgal")) return;
  document.querySelectorAll("[data-rgal]").forEach((root) => {
    const buttons = [...root.querySelectorAll("[data-rgal-filter]")];
    const items = [...root.querySelectorAll("[data-rgal-item]")];
    const status = root.querySelector("[data-rgal-status]");
    const viewer = root.querySelector("[data-rgal-viewer]");
    const photo = viewer.querySelector("[data-rgal-photo]");
    const count = viewer.querySelector("[data-rgal-count]");
    const title = viewer.querySelector("[data-rgal-title]");
    const meta = viewer.querySelector("[data-rgal-meta]");
    const text = viewer.querySelector("[data-rgal-text]");
style.css
:root {
  --rgl-text: #2b211a;
  --rgl-muted: #6b5545;
  --rgl-chip: #ffffff;
  --rgl-line: #e3d3c4;
  --rgl-active: #9a3412;
  --rgl-active-text: #ffffff;
  --rgl-ring: #9a3412;
  --rgl-badge: #ffffff;
  --rgl-badge-text: #2b211a;
  --demo-galerie-realisations-grille-bg: #fbf7f2;
  --demo-galerie-realisations-grille-text: #2b211a;

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