Skip to content

Preference switches in WordPress

A list of settings toggled with switches, each with a description.

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

interrupteurs-preferences.php
<?php
/**
 * Plugin Name: Forge, Interrupteurs de préférences
 * Description: Une liste de réglages activables par interrupteurs, avec description de chaque option. Ajoute la composition « Interrupteurs de préférences » à 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-interrupteurs-preferences
 *
pattern.html
<!-- wp:html -->
<fieldset class="prefs">
        <legend>Notifications</legend>
        <div class="prefs__row">
          <div>
            <label for="pref-news">Lettre d'information mensuelle</label>
            <p id="pref-news-desc">Nouveautés et conseils, une fois par mois.</p>
          </div>
          <input id="pref-news" type="checkbox" role="switch" aria-describedby="pref-news-desc" checked>
        </div>
        <div class="prefs__row">
          <div>
style.css
:root {
  --prefs-bg: #ffffff;
  --prefs-line: #e2e8e4;
  --prefs-text: #142019;
  --prefs-muted: #4e5e55;
  --switch-off: #8a978f;
  --switch-on: #15803d;
  --switch-knob: #ffffff;
  --prefs-ring: #15803d;
  --demo-interrupteurs-preferences-bg: #f3f6f4;
  --demo-interrupteurs-preferences-text: #142019;
}

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

Forms and inputs components in WordPress
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component