Updated on November 10, 2026
To add a WhatsApp button to WordPress without a plugin, all you need is a wa.me link styled with CSS. In block themes (such as Twenty Twenty-Five), paste the code into a Custom HTML block inside the Footer template part, through the Site Editor, and the button shows on every page. In classic themes, use the wp_footer hook in a child theme. For buttons inside your content, the native Buttons block does the job with no code, and GA4 tracks clicks through enhanced measurement or a custom event.
Below are the full snippet, three ways to install it, how to use the Buttons block, and GA4 tracking.
Why skip a plugin just for the button
A WhatsApp button plugin takes two clicks, but it often brings things you did not ask for: stylesheets, scripts, icon fonts and settings screens that load on every page. Each extra plugin is also one more thing to update and one more risk surface.
The button itself is just a link. The code below loads no library and no external image: it is a few lines of HTML and CSS. If you already use a plugin, compare before switching: open the page with your browser’s developer tools (Network tab) and see what it loads.
The snippet: floating button in HTML and CSS
<a class="wa-float"
href="https://wa.me/14155550123?text=Hi%21%20I%20came%20from%20your%20website."
target="_blank"
rel="noopener"
aria-label="Chat on WhatsApp">
<svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false">
<path fill="currentColor" d="M4 3h16a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H9l-5 4v-4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z"/>
</svg>
<span>WhatsApp</span>
</a>
<style>
.wa-float {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 9999;
display: inline-flex;
align-items: center;
gap: 8px;
padding: 12px 18px;
border-radius: 999px;
background: #25d366;
color: #fff;
font: 600 16px/1 system-ui, sans-serif;
text-decoration: none;
box-shadow: 0 4px 12px rgba(0, 0, 0, .2);
}
.wa-float:hover,
.wa-float:focus-visible { filter: brightness(.95); color: #fff; }
.wa-float:focus-visible { outline: 3px solid #128c7e; outline-offset: 3px; }
@media (max-width: 480px) {
.wa-float { right: 12px; bottom: 12px; padding: 12px; }
.wa-float span { display: none; }
}
@media print { .wa-float { display: none; } }
</style>
What each detail does:
- A
wa.melink with the number in international format, digits only, and a URL-encoded message, as the WhatsApp Help Center requires. The format guide is in WhatsApp link with a prefilled message, and the WhatsApp link generator builds the address for you. If you are unsure whether to usewa.meorapi.whatsapp.com/send, see which one to use. - An inline SVG icon (a simple chat bubble), with no file or icon library. It inherits the text color (
currentColor). aria-labelkeeps the button understandable for screen readers when only the icon shows on mobile.focus-visiblegives a visible outline to keyboard users.@media printhides the button when the page is printed.
Change the number and text before publishing, and test the link on a phone.
Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →
Where to paste the code
Option 1: block theme, in the footer (recommended)
In block themes, the footer is a template part repeated on every page. According to the Template Part block documentation, when you change the blocks inside a template part, the editor updates every template that includes it.
- In the dashboard, go to Appearance > Editor > Patterns and open All template parts.
- Open the Footer.
- Add a Custom HTML block (type
/htmlon an empty line). - Paste the snippet, check the preview and save.
Because the button uses position: fixed, it does not matter where in the footer the block sits: it shows in the corner of the screen.
One caveat: according to the Custom HTML block documentation, starting with WordPress 7.0 the block has separate HTML, CSS and JavaScript panels, and the CSS and JavaScript panels are only available to users with the unfiltered_html capability. For users without it (a Contributor, for example), WordPress strips disallowed tags such as <script> and <iframe> on save. Install the button with an administrator account. On WordPress 7.0 or later, you can also put the CSS in the block’s CSS panel instead of the <style> tag.
Option 2: classic theme or version-controlled code, with wp_footer
In classic themes, or if you prefer to keep the code in your repository, use the wp_footer hook, which prints content before the closing body tag. Put it in the functions.php of a child theme (so you do not lose it when the parent theme updates):
<?php
add_action( 'wp_footer', function () {
if ( is_admin() ) {
return;
}
$number = '14155550123';
$text = rawurlencode( 'Hi! I came from your website.' );
$url = "https://wa.me/{$number}?text={$text}";
?>
<a class="wa-float" href="<?php echo esc_url( $url ); ?>"
target="_blank" rel="noopener" aria-label="Chat on WhatsApp">
<span>WhatsApp</span>
</a>
<style>
.wa-float{position:fixed;right:20px;bottom:20px;z-index:9999;padding:12px 18px;
border-radius:999px;background:#25d366;color:#fff;font:600 16px/1 system-ui,sans-serif;
text-decoration:none;box-shadow:0 4px 12px rgba(0,0,0,.2)}
</style>
<?php
} );
rawurlencode() encodes the message, and esc_url() makes sure the URL is output safely in the HTML. For the icon, paste the same <svg> from the earlier snippet inside the link.
Option 3: only on some pages
If the button should appear only on the contact page or on product pages, use the Custom HTML block inside those pages’ content instead of the footer. In functions.php, wrap the output in a condition such as is_page( 'contact' ) or is_singular( 'product' ).
In-content button with the Buttons block
For a call to action in the middle of your text (“Ask us anything on WhatsApp”), you do not need code. The Buttons block is built in:
- Type
/buttonson an empty line and choose Buttons. - Write the button text and, in the block toolbar, use Link to paste the
wa.meaddress. You can also set it to open in a new tab there. - In the sidebar, under Styles, adjust color, typography, border and shadow. The block supports separate styles for the hover, focus and active states.
- Under Advanced, use Additional CSS class(es) to add a class such as
wa-cta(handy for click tracking) and Link relation to add arelvalue such asnoopener.
To reuse the same button across many pages, turn it into a synced pattern: change the number once and every copy updates.
Track clicks in GA4
No code: enhanced measurement
If GA4 enhanced measurement is turned on for your data stream, clicks on links that lead to another domain are logged as the click event, with the link_url, link_domain and outbound parameters (enhanced measurement). Since wa.me is a different domain, clicks on the button are already there. In your report, filter link_domain equal to wa.me.
Limitation: the click event lumps all outbound links together and does not tell the floating button apart from the in-content button.
With a custom event
To separate the buttons and mark the action as a key event, fire an event on click. This script handles every wa.me link on the page, including those in the Buttons block:
document.addEventListener('click', function (e) {
const link = e.target.closest('a[href*="wa.me/"]');
if (!link || typeof gtag !== 'function') return;
gtag('event', 'generate_lead', {
lead_source: link.classList.contains('wa-float') ? 'whatsapp_floating' : 'whatsapp_content',
page_path: location.pathname,
});
});
Put the script in the Custom HTML block’s JavaScript panel (WordPress 7.0 or later, with an administrator account) or print it with wp_footer inside a <script> tag. It assumes the GA4 gtag is already installed on the site. Setting up the key event and custom dimensions is covered in WhatsApp button on your website with GA4 tracking.
From click to conversation
GA4 sees the click, not the message sent. To know how many conversations each page produced, add a short tag to the prefilled message (for example, (SITE-CONTACT)) and read that tag when the message arrives through the official API webhook.
What about WooCommerce?
The contact button works the same way in WooCommerce stores. Automatic order notifications (confirmation, payment, shipping), however, do not come from a button: they are messages the store sends through the API, using approved templates. See WooCommerce with the WhatsApp Business API.
How to do this with Vectalk
The website button is just a link and works with any WhatsApp number. When you want to receive those conversations in your system, reply automatically or send notifications, you need the official WhatsApp API. Vectalk gives you access to the API with coexistence: the number stays in the WhatsApp Business app, and messages that come in through the button also reach your webhook, in Meta’s format. Vectalk has no inbox and no WordPress plugin; customer service happens in your system or in the tool connected to the API. To get started, see getting started with Vectalk and create your account at apps.vectalk.com.br/register.
Frequently asked questions
Do I need a plugin to add a WhatsApp button to WordPress?
No. A wa.me link with CSS is enough. In block themes, paste the snippet into a Custom HTML block in the Footer template part; in classic themes, use the wp_footer hook in a child theme.
The Custom HTML block deleted my code. Why?
The WordPress documentation explains that, for users without the unfiltered_html capability, the block’s content is sanitized and tags such as <script> and <iframe> are removed on save. Install it with an administrator account.
Will the button slow down my site?
The snippet in this article loads no external file: the icon is inline SVG and the styles are a few lines. The impact is minimal, but always check with your browser’s developer tools.
How do I show the button only on mobile?
Flip the media query: set .wa-float { display: none; } by default and show it with display: inline-flex inside @media (max-width: 768px). On desktop the link works too; the WhatsApp Help Center mentions use on WhatsApp Web.
Official sources consulted on November 10, 2026: Buttons block (WordPress documentation), Custom HTML block, Template Part block, wp_footer hook, How to use click to chat (WhatsApp Help Center), GA4 enhanced measurement, GA4 events reference.
Put your business on the official WhatsApp
Create your account, connect your number to the official API (you can keep the app with coexistence) and start serving customers and sending messages.
