Skip to content

Main image gallery with thumbnails in WordPress

A large photo with clickable thumbnails and arrows, for a product page or a property listing.

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-vignettes-principale.php
<?php
/**
 * Plugin Name: Forge, Galerie grande image et vignettes
 * Description: Une grande photo accompagnée de vignettes cliquables et de flèches, pour une fiche produit ou une annonce immobilière. Ajoute la composition « Galerie grande image et vignettes » à 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-vignettes-principale
 *
pattern.html
<!-- wp:html -->
<section class="gvp" data-gvp aria-labelledby="gvp-titre">
        <div class="gvp-stage">
          <div class="gvp-main" role="img" aria-label="Séjour lumineux de 32 m² avec parquet" data-gvp-main style="--gvp-bg: linear-gradient(90deg, transparent 12%, #f7f3ea 12% 38%, transparent 38% 62%, #f7f3ea 62% 88%, transparent 88%) 0 0/100% 55% no-repeat, linear-gradient(180deg, #e9e2d6 0 55%, #b98a5e 55%)"></div>
          <button class="gvp-arrow gvp-arrow-prev" type="button" data-gvp-prev aria-label="Photo précédente"><svg class="gvp-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 5-7 7 7 7"/></svg></button>
          <button class="gvp-arrow gvp-arrow-next" type="button" data-gvp-next aria-label="Photo suivante"><svg class="gvp-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 5 7 7-7 7"/></svg></button>
        </div>
        <p class="gvp-caption" aria-live="polite" data-gvp-caption>Séjour lumineux de 32 m² avec parquet · photo 1 sur 6</p>
        <ul class="gvp-thumbs" role="list" aria-label="Toutes les photos">
            <li>
              <button class="gvp-thumb" type="button" data-gvp-thumb data-gvp-alt="Séjour lumineux de 32 m² avec parquet" aria-label="Photo 1 : Séjour lumineux de 32 m² avec parquet" aria-current="true" style="--gvp-bg: linear-gradient(90deg, transparent 12%, #f7f3ea 12% 38%, transparent 38% 62%, #f7f3ea 62% 88%, transparent 88%) 0 0/100% 55% no-repeat, linear-gradient(180deg, #e9e2d6 0 55%, #b98a5e 55%)"></button>
            </li>
script.js
(() => {
  if (!document.querySelector(".gvp")) return;
  document.querySelectorAll("[data-gvp]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const main = root.querySelector("[data-gvp-main]");
    const caption = root.querySelector("[data-gvp-caption]");
    const thumbs = Array.from(root.querySelectorAll("[data-gvp-thumb]"));
    let index = 0;

    const show = (next) => {
      index = (next + thumbs.length) % thumbs.length;
      const thumb = thumbs[index];
style.css
:root {
  --gvp-card: #ffffff;
  --gvp-text: #1c2230;
  --gvp-muted: #545d6e;
  --gvp-accent: #1e40af;
  --gvp-chip: rgb(255 255 255 / 0.94);
  --demo-galerie-vignettes-principale-bg: #e8ebf2;
  --demo-galerie-vignettes-principale-text: #1c2230;
}

@media (prefers-color-scheme: dark) {
  :root.forge-follows-system:not([data-theme="light"]) {

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
  • Projects sorted by type of work, arranged in tabs that work with the keyboard and screen readers.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component