Skip to content

Contact card with address and map in WordPress

A “Find us” card bringing together address, access, phone, email and opening hours, with an OpenStreetMap map loaded on demand and buttons to call, email, get directions or copy the address.

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

carte-contact-adresse-plan.php
<?php
/**
 * Plugin Name: Forge, Carte de contact avec adresse et plan
 * Description: Une carte « Nous trouver » qui regroupe adresse, accès, téléphone, e-mail et horaires, avec un plan OpenStreetMap chargé à la demande et des boutons pour appeler, écrire, lancer l'itinéraire ou copier l'adresse. Ajoute la composition « Carte de contact avec adresse et plan » à 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-carte-contact-adresse-plan
 *
pattern.html
<!-- wp:html -->
<article class="ccap" aria-labelledby="ccap-titre" data-ccap>
        <div class="ccap__layout">
        <div class="ccap__map" data-ccap-frame>
          <svg class="ccap__streets" viewBox="0 0 400 240" preserveAspectRatio="xMidYMid slice" fill="none" stroke="currentColor" stroke-width="10" stroke-linecap="round" aria-hidden="true"><path d="M-10 70C80 60 160 92 410 48"/><path d="M-10 172C120 150 250 192 410 158"/><path d="M118-10C132 80 108 160 142 250"/><path d="M292-10C268 90 302 170 280 250"/><path d="M-10 118H410" stroke-width="4"/><path d="M200-10V250" stroke-width="4"/></svg>
          <div class="ccap__panel" data-ccap-placeholder>
            <span class="ccap__pin" aria-hidden="true"><svg class="ccap__pin-icon" viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 21s-7-6.2-7-11.5a7 7 0 0 1 14 0C19 14.8 12 21 12 21z"/><circle cx="12" cy="9.5" r="2.5"/></svg></span>
            <p class="ccap__map-text">Le plan interactif est chargé depuis OpenStreetMap seulement si vous le demandez.</p>
            <button class="ccap__btn ccap__btn--primary" type="button" data-ccap-map data-src="https://www.openstreetmap.org/export/embed.html?bbox=4.8235%2C45.7629%2C4.8315%2C45.7669&amp;layer=mapnik&amp;marker=45.7649%2C4.8275" hidden>Afficher le plan</button>
            <a class="ccap__link" href="https://www.openstreetmap.org/?mlat=45.7649&amp;mlon=4.8275#map=17/45.7649/4.8275">Ouvrir le plan sur OpenStreetMap</a>
          </div>
        </div>
script.js
(() => {
  if (!document.querySelector(".ccap")) return;
  document.querySelectorAll("[data-ccap]").forEach((card) => {
    const status = card.querySelector("[data-ccap-status]");
    const say = (message) => {
      status.textContent = "";
      // A fresh text node makes screen readers repeat an identical message.
      requestAnimationFrame(() => {
        status.textContent = message;
      });
    };
style.css
:root {
  --ccap-text: #1f2937;
  --ccap-muted: #4b5563;
  --ccap-card: #ffffff;
  --ccap-soft: #f1f5f9;
  --ccap-line: #e5e7eb;
  --ccap-border: #cbd5e1;
  --ccap-street: #cbd5e1;
  --ccap-accent: #1d4ed8;
  --ccap-accent-hover: #1e40af;
  --ccap-accent-text: #ffffff;
  --ccap-accent-soft: #dbeafe;

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

Cards components in WordPress
  • A single-plan pricing card: struck-through price and discount, a places-left gauge driven by a data attribute, the list of everything included and a booking button that turns into a waiting list once sold out.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three treatment cards in accessible neumorphism: gently raised surfaces, buttons that sink in when activated, a light/dark switch for the block itself. 3:1 outlines and AA text kept.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Four fully clickable workshop cards in a neo-brutalist style: thick border, solid offset shadow and a card that sinks onto its shadow on hover or focus. Pastel tones, dark mode, no JavaScript.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Three brutalist service cards: one-pixel border, hard offset shadow that lifts on hover and sinks on click, large type, accent and dark variants. No JavaScript.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A mobile page to link from your social profiles: portrait, name, priority links (booking, WhatsApp, website, reviews, call), opening hours with an open or closed status, social links and a share button, in dependency-free HTML and CSS.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A seasonal promotion card with a struck-through price and discount that announces by itself whether the offer is coming, how many days are left or that it is over.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component