Skip to content

Energy savings calculator in WordPress

A simulator that estimates the heating bill and the yearly savings in euros from the floor area, current energy and chosen works.

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

calculateur-economies-energie.php
<?php
/**
 * Plugin Name: Forge, Calculateur d’économies d’énergie
 * Description: Un simulateur qui estime la facture de chauffage et l’économie en euros par an selon la surface, l’énergie actuelle et les travaux choisis. Ajoute la composition « Calculateur d’économies d’énergie » à 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-calculateur-economies-energie
 *
pattern.html
<!-- wp:html -->
<form class="cee" data-cee data-cee-need="150" aria-labelledby="cee-titre">
        <div class="cee-inputs">
          <h2 class="cee-title" id="cee-titre">Combien économiser sur votre chauffage ?</h2>
          <div class="cee-field">
            <label class="cee-label" for="cee-surface">Surface chauffée : <output for="cee-surface" data-cee-surface-out>110 m²</output></label>
            <input class="cee-range" id="cee-surface" name="surface" type="range" min="40" max="250" step="5" value="110">
          </div>
          <div class="cee-field">
            <label class="cee-label" for="cee-energie">Chauffage actuel</label>
            <select class="cee-select" id="cee-energie" name="energie">
                <option value="gaz" data-price="0.12" data-yield="0.9">Chaudière gaz</option>
script.js
(() => {
  if (!document.querySelector(".cee")) return;
  document.querySelectorAll("[data-cee]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const form = root;
    const need = Number(form.dataset.ceeNeed);
    const ELEC = 0.25;
    const COP = 3;
    const euro = new Intl.NumberFormat("fr-FR", { style: "currency", currency: "EUR", maximumFractionDigits: 0 });
    const out = (name) => form.querySelector(`[data-cee-${name}]`);

    const update = () => {
style.css
:root {
  --cee-card: #ffffff;
  --cee-text: #132a1c;
  --cee-muted: #46594c;
  --cee-line: #cfdcd3;
  --cee-field: #ffffff;
  --cee-accent: #166534;
  --cee-result: #14532d;
  --cee-result-text: #f0fdf4;
  --cee-result-muted: #bbe5c8;
  --cee-cta: #f0fdf4;
  --cee-cta-text: #14532d;

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

Features components in WordPress
  • Three cards in saturated flat colours (yellow, pink, electric blue) with high-contrast text and a dark variant. Every colour pair is measured at AA: 5.5:1 at worst.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Six features as frosted glass cards over a slowly drifting aurora mesh gradient. Pause button, still background under prefers-reduced-motion, CSS and a light script.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • The key message stays pinned while the background changes colour and illustration at each scroll step. CSS sticky, a light script, stacked cards as fallback under prefers-reduced-motion.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A six-cell bento grid: key figures, SVG sparklines, a quote and icons. All the text is in the HTML and the animation is CSS only, with no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A two-offer table: checked rows, a column highlighted from top to bottom and one call-to-action button per offer. Pure HTML and CSS, no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A magazine-style article: title band, standfirst, drop cap, subheadings and a pull quote, set in three columns of equal height. Pure CSS, no script at all.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component