Skip to content

Four-level alerts in WordPress

The four classic interface messages: information, success, warning and error.

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

alertes-quatre-niveaux.php
<?php
/**
 * Plugin Name: Forge, Alertes à quatre niveaux
 * Description: Les quatre messages classiques d'une interface : information, succès, avertissement et erreur. Ajoute la composition « Alertes à quatre niveaux » à 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-alertes-quatre-niveaux
 *
pattern.html
<!-- wp:group {"className": "levels", "layout": {"type": "default"}} -->
<div class="wp-block-group levels"><!-- wp:group {"className": "levels__item levels__item--info", "layout": {"type": "default"}} -->
<div class="wp-block-group levels__item levels__item--info"><!-- wp:html -->
<svg aria-hidden="true" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg>
<!-- /wp:html -->
<!-- wp:group {"layout": {"type": "default"}} -->
<div class="wp-block-group"><!-- wp:paragraph {"className": "levels__title"} -->
<p class="levels__title">Information</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>Votre essai gratuit se termine dans 5 jours. Vos données sont conservées si vous choisissez une formule.</p>
<!-- /wp:paragraph --></div>
style.css
:root {
  --lv-info-bg: #eff6ff;
  --lv-info-line: #bfdbfe;
  --lv-info: #1e40af;
  --lv-ok-bg: #f0fdf4;
  --lv-ok-line: #bbf7d0;
  --lv-ok: #166534;
  --lv-warn-bg: #fffbeb;
  --lv-warn-line: #fde68a;
  --lv-warn: #92400e;
  --lv-err-bg: #fef2f2;
  --lv-err-line: #fecaca;

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

Toasts and alerts components in WordPress
  • A banner that warns visitors when they lose the network and announces when it is back, using browser events, with no request.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A bell with an unread badge that opens a notification panel: icons by type, read and unread items told apart, and a "Mark all as read" button.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three callouts for technical documentation: note, tip and warning.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A notice warning of a scheduled service interruption, with date, time and impact.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A dashed callout highlighting an offer and its code, with the end date.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An announcement bar at the top of the page with a link and a button to close it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component