Skip to content

Size guide in WordPress

A size picker with a modal guide: a measurement table and a size recommended from the chest measurement, in one click.

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

guide-des-tailles.php
<?php
/**
 * Plugin Name: Forge, Guide des tailles
 * Description: Un choix de taille avec guide en fenêtre modale : tableau des mesures et taille conseillée d’après le tour de poitrine, en un clic. Ajoute la composition « Guide des tailles » à 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-guide-des-tailles
 *
pattern.html
<!-- wp:html -->
<form class="gdt" data-gdt data-gdt-ranges="{&quot;XS&quot;:[80,84],&quot;S&quot;:[85,90],&quot;M&quot;:[91,97],&quot;L&quot;:[98,105],&quot;XL&quot;:[106,114]}" aria-labelledby="gdt-titre">
        <h2 class="gdt-title" id="gdt-titre">Veste de travail en coton bio</h2>
        <fieldset class="gdt-fs">
          <legend class="gdt-legend">Taille : <strong data-gdt-picked>non choisie</strong></legend>
          <div class="gdt-sizes">
            <label class="gdt-size"><input class="gdt-radio" type="radio" name="gdt-taille" value="XS"><span>XS</span></label>
            <label class="gdt-size"><input class="gdt-radio" type="radio" name="gdt-taille" value="S"><span>S</span></label>
            <label class="gdt-size"><input class="gdt-radio" type="radio" name="gdt-taille" value="M"><span>M</span></label>
            <label class="gdt-size"><input class="gdt-radio" type="radio" name="gdt-taille" value="L"><span>L</span></label>
            <label class="gdt-size"><input class="gdt-radio" type="radio" name="gdt-taille" value="XL"><span>XL</span></label>
          </div>
script.js
(() => {
  if (!document.querySelector(".gdt")) return;
  document.querySelectorAll("[data-gdt]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const form = root;
    const ranges = JSON.parse(form.dataset.gdtRanges);
    const dialog = form.querySelector("[data-gdt-dialog]");
    const opener = form.querySelector("[data-gdt-open]");
    const input = form.querySelector("#gdt-poitrine");
    const advice = form.querySelector("[data-gdt-advice]");
    const choose = form.querySelector("[data-gdt-choose]");
    const status = form.querySelector("[data-gdt-status]");
style.css
:root {
  --gdt-card: #ffffff;
  --gdt-text: #142231;
  --gdt-muted: #475769;
  --gdt-line: #cdd7e1;
  --gdt-soft: #eef4f9;
  --gdt-ring: #0e5a8a;
  --gdt-accent: #0e5a8a;
  --gdt-accent-text: #ffffff;
  --demo-guide-des-tailles-bg: #e8eef3;
  --demo-guide-des-tailles-text: #142231;
}

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

E-commerce components in WordPress
  • A limited-time offer bar: countdown to a fixed date, one-click copyable promo code and a fallback message once the offer is over.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A sales card showing the discount that grows with the cart amount (-10% from €50, -15% from €100…) with a progress bar towards the next tier.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A Christmas gift guide filtered by budget and theme, with the number of ideas announced and an empty state offering to show everything again.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • The last order dates for delivery before Christmas, per shipping method, with the days left worked out from the visitor’s date.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A cart that shows live how much is left to add for free shipping, with a progress bar and recalculated totals.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A colour and size picker for a product page: the visual, price and stock follow the choice, and sold-out sizes are disabled.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component