Click-to-load video gallery in WordPress
YouTube videos shown as thumbnails: the player only loads on click, to respect privacy and keep the page light.
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
The code in WordPress
<?php
/**
* Plugin Name: Forge, Galerie vidéo à chargement au clic
* Description: Des vidéos YouTube présentées en vignettes : le lecteur n’est chargé qu’au clic, pour respecter la vie privée et alléger la page. Ajoute la composition « Galerie vidéo à chargement au clic » à 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-video-vignettes
*<!-- wp:html -->
<section class="gvv" data-gvv aria-labelledby="gvv-titre">
<p class="gvv-eyebrow">Ciné-club de l’Isle · séance du jeudi</p>
<h2 class="gvv-title" id="gvv-titre">Courts métrages libres de la Blender Foundation</h2>
<p class="gvv-note">Les vidéos sont hébergées par YouTube. Rien n’est chargé avant votre clic ; le lecteur vient alors de youtube-nocookie.com, qui peut déposer des cookies. Films sous licence Creative Commons BY.</p>
<ul class="gvv-grid" role="list">
<li class="gvv-card">
<div class="gvv-media" data-gvv-media>
<button class="gvv-poster" type="button" data-gvv-play data-gvv-id="eRsGyueVLvQ" data-gvv-title="Sintel" style="--gvv-bg: radial-gradient(circle at 70% 30%, #fde68a 0 7%, transparent 8%), linear-gradient(180deg, #7c93a8 0 45%, #e5e7eb 45% 70%, #9ca3af 70%)">
<span class="gvv-play"><svg class="gvv-play-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 5.5v13l10.5-6.5z" fill="currentColor"/></svg></span>
<span class="gvv-sr">Lire la vidéo Sintel (charge le lecteur YouTube)</span>
</button>(() => {
if (!document.querySelector(".gvv")) return;
document.querySelectorAll("[data-gvv]").forEach((root) => {
const on = (el, type, fn) => el.addEventListener(type, fn);
root.querySelectorAll("[data-gvv-play]").forEach((button) => {
on(button, "click", () => {
const frame = document.createElement("iframe");
frame.src = `https://www.youtube-nocookie.com/embed/${button.dataset.gvvId}?autoplay=1&rel=0`;
frame.title = `Vidéo : ${button.dataset.gvvTitle}`;
frame.allow = "autoplay; encrypted-media; picture-in-picture; fullscreen";
frame.referrerPolicy = "strict-origin-when-cross-origin";
button.closest("[data-gvv-media]").replaceChildren(frame);:root {
--gvv-card: #ffffff;
--gvv-text: #1e1b2e;
--gvv-muted: #575270;
--gvv-accent: #6d28d9;
--gvv-soft: #f1ecfb;
--demo-galerie-video-vignettes-bg: #ece9f3;
--demo-galerie-video-vignettes-text: #1e1b2e;
}
@media (prefers-color-scheme: dark) {
:root.forge-follows-system:not([data-theme="light"]) {Free component: copy it freely, including for commercial projects.
Other galleries and carousels components in WordPress
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

An Instagram-style square grid with a profile header and captions on hover, served by your own site: no social network script or cookie.
- Tailwind
- React
- CSS
- WordPress

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

A large photo with clickable thumbnails and arrows, for a product page or a property listing.
- Tailwind
- React
- CSS
- WordPress

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

Projects sorted by type of work, arranged in tabs that work with the keyboard and screen readers.
- Tailwind
- React
- CSS
- WordPress