โ† Blog & guides
Tutorial4 min read

Web Push Notifications for WordPress: A Complete Setup Guide

Add web push to WordPress step by step โ€” SDK snippet, service worker, opt-in prompt, and auto-sending on new posts. Beginner-friendly tutorial.

Web push notifications let you reach visitors directly on their desktop or Android device โ€” even after they've left your site. No email address, no app install. For a WordPress blog or store, it's one of the fastest ways to bring readers back when you publish something new.

This guide walks through the whole setup: adding the SDK snippet, registering the service worker, showing an opt-in prompt, and sending a notification automatically on every new post. You don't need to be a developer to follow along.

How web push actually works

Before the steps, here's the 30-second model so the setup makes sense:

You don't have to manage VAPID keys or run a server yourself. A push SaaS like relaybell handles the signing and delivery โ€” you just add a snippet and press send.

Step 1: Add the SDK snippet

Sign up for a web push provider and create a site. You'll get a short <script> snippet that loads the SDK. In WordPress, the cleanest way to add it across every page is via your theme's header.

The simplest no-code path:

If you use a child theme (recommended), you can also hook it in via functions.php:

add_action('wp_head', function () {
  echo '<script src="https://cdn.relaybell.com/sdk.js" data-site="YOUR_SITE_ID" async></script>';
});

Using a child theme means a theme update won't wipe your change.

Step 2: Install the service worker

The service worker is a single JavaScript file that must live at your domain root โ€” for example https://yoursite.com/sw.js. Browsers only allow a worker to control pages at or below its own path, so placing it at the root lets it cover your whole site.

Your provider gives you this file. Upload it to your WordPress root directory (the same folder as wp-config.php) using your host's File Manager or SFTP. Then confirm it loads by visiting https://yoursite.com/sw.js โ€” you should see code, not a 404.

A couple of things that trip people up:

Step 3: Configure the opt-in prompt

This is where most of your results are won or lost. The native browser permission dialog is a one-shot decision โ€” if someone clicks "Block," you can't ask again. So treat it carefully.

Best practices for the prompt:

Most providers, relaybell included, give you a visual editor for the prompt text, timing, and delay โ€” no code needed. Typical opt-in rates land in the low single digits to around 10% of visitors, depending on how relevant your offer is.

Step 4: Send automatically on new posts

Now the payoff: notify every subscriber the moment you hit Publish.

Two common approaches:

A minimal example using functions.php:

add_action('publish_post', function ($post_id) {
  $post = get_post($post_id);
  wp_remote_post('https://api.relaybell.com/v1/send', [
    'headers' => ['Authorization' => 'Bearer YOUR_API_KEY'],
    'body' => json_encode([
      'title' => get_the_title($post),
      'body'  => wp_trim_words($post->post_content, 20),
      'url'   => get_permalink($post),
    ]),
  ]);
}, 10, 1);

Tips to get clicks, not blocks

That's the full loop: snippet, service worker, opt-in, and automated sends. Once it's wired up, every new post quietly pulls returning readers back โ€” for free.

Ready to try web push? Get started with relaybell โ€” free to deliver, set up in minutes.