Add WhatsApp to a WordPress site
Three things a WordPress site usually wants from WhatsApp, and how to set up each — including the form-to-WhatsApp bridge that most sites get wrong by tying it to email delivery.
A WordPress site usually wants three things from WhatsApp, and they are separate jobs: a chat widget for visitors, contact form submissions forwarded to a phone, and a click-to-chat button. Here is each, with and without a plugin.
Put the chat widget on the site
A widget lets a visitor start a conversation without leaving the page or handing over their number, which is most of why it outperforms a click-to-chat button — see the comparison.
With the plugin
Install, paste your widget key, done. It loads the script on every page and keeps it out of the admin area, which a hand-placed snippet usually gets wrong.
Without
Append the snippet in your theme’s functions file. Use a child theme, or the next theme update deletes it.
add_action( 'wp_footer', function () {
// Admin pages do not need a customer chat widget, and loading it there
// is how you end up with a support conversation started by mistake.
if ( is_admin() ) {
return;
}
?>
<script
src="https://wavesenda.com/widget.js"
data-wavesenda-key="wsk_your_key_here"
data-api="https://api.wavesenda.com/api"
async></script>
<?php
} );Then restrict the widget to your own domains in the console, or somebody can embed your chat on their site and collect conversations meant for you.
Forward contact form submissions
The most useful and least implemented of the three. Somebody fills in Contact Form 7 or WPForms, and the enquiry arrives on WhatsApp rather than in an inbox nobody opens until Tuesday.
One detail that matters more than it sounds: hook the submission, not the mail sent event. Tying WhatsApp delivery to email success means a shared host with broken mail silently costs you every enquiry — the visitor sees success, the email fails, and no message is sent either.
add_action( 'wpcf7_submit', function ( $form, $result ) {
// Accept both mail_sent and mail_failed. The submission is what we care
// about; whether the site's email happened to work is a separate matter.
$status = isset( $result['status'] ) ? $result['status'] : '';
if ( 'mail_sent' !== $status && 'mail_failed' !== $status ) {
return;
}
$submission = WPCF7_Submission::get_instance();
if ( ! $submission ) {
return;
}
$data = $submission->get_posted_data();
$text = sprintf(
"New enquiry from %s\n%s\n\n%s",
isset( $data['your-name'] ) ? $data['your-name'] : 'someone',
isset( $data['your-email'] ) ? $data['your-email'] : '',
isset( $data['your-message'] ) ? $data['your-message'] : ''
);
wp_remote_post( 'https://api.wavesenda.com/api/v1/messages/send/', array(
'timeout' => 5,
'blocking' => false, // never make a visitor wait on our API
'headers' => array(
'Authorization' => 'Bearer ' . WAVESENDA_API_KEY,
'Content-Type' => 'application/json',
),
'body' => wp_json_encode( array(
'session' => WAVESENDA_SESSION,
'to' => '+237670000000',
'type' => 'text',
'text' => $text,
) ),
) );
}, 10, 2 );blocking => false is deliberate. A visitor pressing Submit should never wait on a third-party API, and an API having a slow morning should never make your form look broken.
Put the key in wp-config.php as a constant, not in the theme file, and not in version control.
Add a click-to-chat button
For visitors who would rather have the thread on their own phone. It belongs in the opposite corner from the chat widget so the two do not fight for one spot.
add_shortcode( 'whatsapp_button', function ( $atts ) {
$a = shortcode_atts( array(
'number' => '237670000000',
'text' => 'I have a question about',
'label' => 'Message us',
), $atts );
return sprintf(
'<a class="wa-button" href="https://wa.me/%s?text=%s" target="_blank" rel="noopener noreferrer">%s</a>',
rawurlencode( $a['number'] ),
rawurlencode( $a['text'] ),
esc_html( $a['label'] )
);
} );Prefill the message with something specific. A visitor who arrives in WhatsApp having said “Hi” has started nothing; one who arrives naming the product has started the conversation.
WooCommerce order notifications
If you sell, this is where the value is. Order placed, shipped, out for delivery — covered in full in the WooCommerce post, including which moments to send and which to skip.
Things that go wrong
| Symptom | Cause |
|---|---|
| Widget does not appear | Domain not in the allow list, or a caching plugin serving an old page |
| Form messages stop after an update | The snippet was in a parent theme and got overwritten |
| Enquiries arrive twice | Both a plugin and a manual hook are firing |
| Form feels slow | A blocking HTTP call in the submit handler |
| Nothing arrives, no error | Usually the number has no WhatsApp account — check it |
Full snippet and plugin details in the website chat docs and the integrations page.
Common questions
Do I need a plugin to add WhatsApp to WordPress?
No. The chat widget is a script tag, and form forwarding is one hook. A plugin is mostly convenience — it keeps the snippet out of your theme so a theme update cannot delete it, which is the commonest way a hand-placed one disappears.
Why did my contact form stop sending to WhatsApp?
Most often a theme update overwrote a snippet in the parent theme. Use a child theme or a site-specific plugin. The other common cause is hooking the mail-sent event, so broken site email silently stops WhatsApp delivery too.
Will the widget slow my site down?
It should not — the script loads asynchronously after the page and does not block rendering. What does cause slowness is a blocking API call inside a form submit handler, which makes visitors wait on a third party before they see a confirmation.
Can I show the widget on some pages only?
Yes, either with page rules in the console or by conditionally loading the snippet in your theme. Common choices are hiding it on checkout, where it competes with the purchase, and on legal pages where nobody wants a chat.
Is it safe to put my API key in WordPress?
Put it in wp-config.php as a constant, never in a theme file and never in version control. Treat it like a database password: anyone with it can send messages as you, so scope it to what the site actually needs.