Cookie consent on WordPress without a banner and without Borlabs

At a Glance
Silvertrail is my own consent plugin for WordPress. I set it up on this site with Claude Code. Visitors see no cookie banner, because every video and every map shows its own placeholder first.

Compared with Borlabs, Silvertrail is small and lives in code. Its API let Claude build my extras and test them without me.

In the middle of November, my own site still loaded Google before anybody had agreed to anything. Every travel map pulled in Google Maps. Posts embedded videos from YouTube. The site had no privacy policy either.

That was awkward, because I had spent the first half of the month writing a consent plugin. Silvertrail is a plugin I developed. It is free on WordPress.org. So this post is about putting my own plugin on my own site.

I did not want a cookie banner. Nothing on the site needs consent for its own sake. Only the videos and the maps do.

Only the videos and the maps need consent. A banner on every page is too much for that.

What my site loads from others

Silvertrail lists six services on my site. Four of them show content. YouTube and Spotify play the videos and podcast episodes in my posts. SRF, RTS, RSI and RTR are the Swiss public broadcasters. A few posts embed their videos. Google Maps draws the travel maps on my trip and location pages.

The other two count visits. GoatCounter is an open-source visit counter. It sets no cookie and stores nothing in the browser. Cloudflare is the network in front of my site, so it delivers every page. Its Web Analytics measures how fast the pages load. It works without cookies too.

The first four tell another company about the visit as soon as they load. In the EU, the EEA and the UK, a visitor has to agree to that first. I treat the two counters as exempt, because neither of them stores anything in the browser.

Why there is no banner

Silvertrail shows its banner only when a service has no other place to get consent. A YouTube video has such a place. Silvertrail replaces the video with a placeholder. The placeholder names YouTube and has a button that says “Load content”. The video loads when the visitor clicks that button.

A tracking script is different. It sits in the page head, so there is nothing to click. A site with such a script needs the banner. My site has none, so Silvertrail never shows the banner here. A feature test fails as soon as I add a service that needs it.

A video can wait behind its own placeholder. A tracking script cannot, so it needs the banner.

The setup is one PHP class

Silvertrail keeps its setup in code. Code also wins over anything set in the admin. That suits me, and it suits Claude Code even more. Claude can read a file, change it and test it. A settings page gives it only forms to click through.

The full documentation ships inside the plugin, in a folder called docs/. So an agent reads the version that the site runs. It does not rely on an older version from its training data.

Claude can read a file, change it and test it. A settings page gives it only forms to click through.

On my site, the setup is a class called Consent in my site plugin. I register each service with one call. YouTube is a preset, so its ID is enough. For Spotify, I add the provider, the purpose and the host:

add_action('silvertrail_register', function (): void {
    silvertrail_register_service('youtube', []);

    silvertrail_register_service('spotify', [
        'group' => 'external-media',
        'name' => 'Spotify',
        'provider' => 'Spotify AB, Regeringsgatan 19, 111 53 Stockholm, Sweden',
        'purpose' => 'Plays embedded podcast episodes.',
        'privacy_url' => 'https://www.spotify.com/legal/privacy-policy/',
        'hosts' => ['open.spotify.com'],
    ]);
});

I set the options in one filter. I turned the floating button off, because my footer already has a link. I turned the consent records off too, because nothing on this site needs them.

add_filter('silvertrail_settings', function (array $settings): array {
    $settings['floating_button'] = 'never';
    $settings['require_choice'] = false;
    $settings['records'] = false;

    return $settings;
});

Claude tests its own work

How fast I could set up the plugin was only half the story. Silvertrail also gives an agent several ways to check its own work. That is why I could let Claude run without watching every step.

The first check is a command, wp silvertrail validate. It builds the whole setup and reports every problem in it: an unknown key, an invalid value, a service in a group that does not exist. If it finds problems, it fails and prints the count. So Claude runs it after each change until it reports none.

Two more commands show the result. wp silvertrail services lists every service. wp silvertrail settings lists every setting and where its value comes from: code, admin or default.

The second check runs in a real browser. Silvertrail ships a Playwright helper called expectConsentWorks(). It opens a page as a first-time visitor. Then it declines, accepts everything and accepts each service on its own. It fails with one line for every problem it finds.

On my site, make test-consent runs that helper. My test also sets Cloudflare’s country header to Germany, to the US and to nothing. That covers a visitor who has to agree first, one who can opt out later and one whose country is unknown.

The JavaScript API helps with testing too. window.silvertrail.reset() forgets the visitor’s choice, so the next page view is a first visit again. trail() lists what the page held back and which other hosts it loaded from. In Chrome with WebMCP switched on, an agent gets the same steps as five tools.

The validate command fails and prints the number of problems. Claude runs it until it reports none.

What I built on top

The defaults covered the videos and podcasts in my posts. I added four things myself. Each of them is small and easy to implement. This lets me customise the little details to my needs.

A map that is not an iframe

My travel maps use Google’s JavaScript API. That is a script, not an iframe, so Silvertrail cannot swap it for a placeholder by itself. I print Silvertrail’s own placeholder inside the map container and keep it hidden. A small script of mine then decides before Google’s script loads.

The map loads directly if the visitor allowed Google Maps before. It also loads at once in a country where an opt-out is enough. In every other case, my script shows the placeholder. The map then loads after a click.

The placeholder is Silvertrail’s own markup. So it looks the same on a map as on a video. I fit it over the map with two custom properties, which I can include easily with the tools given:

.trip-map-consent .silvertrail-embed {
    --silvertrail-embed-ratio: auto;
    --silvertrail-embed-width: 24rem;
}

Opt-in or opt-out, by country

Silvertrail does not detect countries. This is written in the documentation. It offers an event instead, called silvertrail:before-prompt. Silvertrail fires that event for a new visitor before it shows anything. My site answers it:

export async function answer(asks) {
    return (await asks()) ? 'prompt' : 'accept-all';
}

window.addEventListener('silvertrail:before-prompt', (event) => {
    event.detail.respondWith(answer(() => regionAsks('/wp-json/mawi/v1/region')));
});

regionAsks() calls a small REST route on my site. The route reads a header called CF-IPCountry. Cloudflare adds that header to every request and puts the visitor’s country in it.

I answer accept-all for seven countries: Switzerland, the US, Australia, New Zealand, Singapore, Hong Kong and Israel. An opt-out is enough there. So videos and maps load directly. Visitors can opt out under Cookie settings in the footer.

Every other country is opt-in. Visitors there have to click before a video or a map loads. I treat three more cases as opt-in. The first is a visitor whose country is unknown. The second is a region check that takes longer than three seconds. The third is a browser that sends Global Privacy Control, a setting that tells websites not to sell or share the visitor’s data.

Silvertrail does not detect countries. My site reads the country from a header that Cloudflare adds.

One click for all media

A visitor in the EU allows one YouTube video. The next Spotify podcast still shows a placeholder. I wanted one button that allows all of them at once.

add_filter('silvertrail_embed_actions', function (array $actions): array {
    $actions[] = ['label' => __('Always allow all external media', 'mawi'), 'grant' => 'external-media'];

    return $actions;
});

The button allows the whole external-media group. That covers YouTube, Spotify, the broadcasters and the map. I gave the button the same name as the group has under Cookie settings. A visitor can switch it off again there.

My footer has a link called Cookie settings. It is a normal menu item that points to #silvertrail. Silvertrail opens its settings dialog for any link that ends this way. In the theme, the footer pattern now prints a menu instead of hard-coded links, so I can edit it in the Site Editor.

I also renamed the dialog to Cookie settings with the silvertrail_texts filter. Now the link and the dialog carry the same name.

What worked out of the box

Most of it needed nothing from me. YouTube videos sat behind a placeholder as soon as I activated the plugin, because YouTube is a preset. A checkbox on the placeholder lets the visitor always allow that provider. The settings dialog took its colours, corners and buttons from my theme’s theme.json. I set no design value for it.

Page caching needed no setup either. My site uses LiteSpeed Cache, the caching plugin for my host’s web server. Silvertrail renders every embed blocked on the server. The browser then activates it for each visitor. So one visitor’s choice never ends up in the next visitor’s page.

Page caching needed no extra setup or adjustments

What loads before a choice

A visitor in Germany sees no banner. Nothing from Google, YouTube or Spotify loads until they consent. A visitor in Switzerland or the US gets videos and maps right away. They can opt out under Cookie settings in the footer.

Some browsers send Global Privacy Control. For them, videos and maps stay behind their placeholders in every country.

Cloudflare’s analytics is the exception. Cloudflare adds its script on its own servers, outside my code, so my site cannot hold it back. It runs on every visit. It sets no cookie and stores nothing in the browser. Silvertrail lists it under Statistics, next to GoatCounter. My privacy policy names both.

The list of countries is my own reading of the rules. It is not legal advice.

In Germany, nothing from Google, YouTube or Spotify loads before a consent.

How it compares to Borlabs

Borlabs Cookie is the paid plugin I compare Silvertrail with.

Borlabs does a lot. Almost all of it is configured in the WordPress admin. It has services, content blockers, script blockers and style blockers. It has a library of packages to install. It offers many presets for the look of the dialog. For me that is too much. So many settings and features make updates and custom styling complicated.

Silvertrail goes the other way. It is small: the front end gets one script and one stylesheet. The setup lives in code, so it sits in git next to its tests. Whatever is missing, I add with a filter or a few lines of JavaScript. The four additions in this post are examples of that.

Borlabs is configured in the admin. Silvertrail is configured in code that sits in git next to its tests.

The API is the bigger difference. Borlabs documents about 45 PHP filters. They change what the admin already holds. I found none that registers a service in code. Its JavaScript API has three functions for consent. It has no function that opens the dialog again. The documentation suggests a CSS class on a link instead.

Silvertrail has a solid API on both sides. In PHP, I register services and call silvertrail_has() to check whether a visitor allowed one. In the browser, window.silvertrail reads and changes the choice with has(), grant(), revoke() and open(). Two events report a new choice and let my code answer before the banner opens. The map, the country check and the button in this post are built on that API.

Borlabs has features that Silvertrail lacks. One is the IAB framework that some ad networks require. A site that needs it, should use Borlabs or alternatives. Borlabs costs €49 a year for one site, before VAT. Silvertrail is free with an honour licence, supporting continued work and improvements.


Conclusion
I wanted consent on my own site without a cookie banner. Silvertrail made that possible, because every video and every map shows its own placeholder first. Visitors in the EU or the UK have to click before the content loads. Visitors in Switzerland or the US see it right away and can opt out later.

The setup was fast, because all of it lives in code. Claude Code could set it up, extend it and test it without me. Most features worked out of the box. My own additions took a few lines each.

Borlabs has more features, but most of them are configured in the admin. For my site, I prefer a small plugin with a solid API that an agent can work with.

Tagged as

I’m curious about projects like this. Got one? Tell me about it

Cookie settings

We use cookies and similar technologies. Some are needed for this site to work. Everything else only runs if you agree.