Silvertrail

Description

Nothing loads until visitors say yes. Silvertrail is a small cookie banner that blocks trackers and embeds until the visitor agrees, and saying no is as easy as saying yes. «Accept all» and «Only essential» sit side by side at the same size, and a third button opens the choice per group and per service, with the provider, the purpose and a link to its privacy policy.

The banner only appears when the site uses something that needs consent. A site whose only services are embeds, or whose services are all marked exempt, shows no banner at all.

Built for developers and their agents

Set everything in PHP and check it on the shell. The admin keeps only the decisions a site owner makes.

  • Code wins over the admin. One filter sets any setting, and the settings page marks each field that code sets.
  • Agents work on the shell. wp silvertrail services and wp silvertrail settings show every service and each setting with its source, and wp silvertrail validate reports what is wrong, so an agent can check its own work.
  • Prompts are built in. The admin copies a prompt to style the banner, and the Leak check writes one for the services it finds.

One call turns on a preset, and the official tag waits for consent:

add_action( 'silvertrail_register', function () {
    silvertrail_register_service( 'google-tag-manager', array( 'tag_id' => 'GTM-XXXXXXX' ) );
} );

Any script you mark with type="text/plain" data-silvertrail="service" waits as well. Silvertrail runs it after consent and keeps the order of inline and external scripts. A script that a theme or plugin enqueues waits once you list its handle under a service.

The README on GitHub is the complete reference.

Styled by your theme, or by you

Out of the box, the banner looks like part of the site. Change a few values or replace the whole design, as far as the project needs.

  • With no setup, the banner reads its colours, corners and buttons from the theme’s theme.json.
  • The silvertrail_design filter changes single values, such as a colour, the corners or the buttons.
  • A silvertrail/silvertrail.css or your own templates in the theme replace the defaults. Settings › Silvertrail › Banner copies a prompt that has an AI assistant write that stylesheet.

Batteries included

The integrations most sites need are built in, so setting it up mostly means ticking boxes.

  • It supports the WP Consent API, so plugins that read the API follow the visitor’s choice.
  • It sets the Google Consent Mode v2 default before any Google tag, and every choice updates it. Google tags stay blocked until consent, and developers can switch to Advanced mode in code.
  • YouTube, Vimeo and Google Maps embeds wait behind a placeholder from the moment the plugin is active, and so do embeds from every host you register. The placeholder asks in place, loads the embed once or remembers the service, and opens no banner.
  • The Leak check, under Settings › Silvertrail › Tools, opens pages as a first-time visitor, declines, agrees to each service on its own and loads them again. It lists what runs without consent and what starts only after a reload, with what to do about each. It writes a prompt to paste into an AI assistant, which asks for the provider, purpose and privacy policy of each service. A Playwright helper in the plugin’s testing folder runs the same check in CI.

Also in the box

  • Presets print the official tags of Google Tag Manager, Google Analytics, Google Ads, the LinkedIn Insight Tag and the Meta Pixel once you turn one on and enter its ID.
  • It works behind any page cache, as the next section explains.
  • A browser that sends Global Privacy Control gets «only essential» without a banner.
  • It asks every visitor again when the set of services changes.
  • It keeps optional records of each decision: a random consent ID, the choices and the time, with no IP address.
  • A link, block or shortcode reopens the preferences, and an optional floating button does the same in a corner of the page.
  • The preferences show the visitor what the current page held back and which other hosts it loaded from.
  • Each site of a multisite network keeps its own cookie.
  • The front end loads one script of 15 KB, under 5 KB compressed, and no jQuery.

Page caching

The server renders every gated script and embed blocked, whatever the visitor chose, and the browser activates them on each page view. So a cached page never hands one visitor’s consent to the next, and page caches need no extra configuration.

What it does not do

Silvertrail does not implement the IAB Transparency and Consent Framework, so an ad network that requires a TCF consent string needs a different banner. It does not detect countries either. A site that treats regions differently decides in the silvertrail:before-prompt hook, as the FAQ shows. It does not crawl the site for cookies. The Leak check looks at the pages you list and shows what they actually load.

Free, with an honour licence

Silvertrail is free. When you are paid to put it on a client’s site, consider supporting its development with a site licence at https://marcwieland.name/support/: 29 a year per site, or 199 a year for an agency with any number of sites, in dollars or euros. The licence works on your honour. It adds nothing and withholds nothing, and nothing checks whether you bought one. There is no pro version and no hosted service, and there will be none. The money pays for the upkeep.

Need something it does not do?

Marc Wieland, the developer of Silvertrail, builds new functionality for it as paid work on request. This is feature development, not technical support. Write to silvertrail@marcwieland.name with the site and what it should do. The code is not proprietary, and when most users would benefit from a feature, it goes into the free plugin. That way, the feature one site needs and can fund also helps every other site that runs Silvertrail and gives something back to the WordPress ecosystem.

Privacy

Silvertrail sets one first-party cookie, silvertrail (on the other sites of a multisite network silvertrail_ and the site ID), which holds the chosen services, the version of the settings and the time of the decision. It lasts six months by default, and a developer changes the lifetime with the silvertrail_settings filter. With records turned on, the cookie also holds a random consent ID, and each decision is stored in a database table with that ID, the choices and the time. Silvertrail never stores an IP address or browser details. The plugin itself contacts no outside service. The services a site turns on load from their providers only after the visitor agrees, as the next section lists.

External services

Each tracker preset below connects to its provider only when an admin turns it on, and only after the visitor agrees to that service. The provider then receives what a browser sends with every request, such as the IP address, the browser details and the address of the page, plus whatever its own code collects. In Consent Mode Advanced, which a developer turns on in code, the Google tags load before consent and send cookieless pings.

  • Google Tag Manager, Google Analytics and Google Ads load the Google tag from googletagmanager.com with the ID entered in the settings. Provided by Google: terms, privacy policy.
  • The LinkedIn Insight Tag loads from snap.licdn.com with the partner ID. Provided by LinkedIn: terms, privacy policy.
  • The Meta Pixel loads from connect.facebook.net with the pixel ID. Provided by Meta: terms, privacy policy.
  • The YouTube, Vimeo and Google Maps presets start switched on, but they load nothing themselves. They hold back embeds the site already contains and let the browser load them from youtube.com, vimeo.com or google.com once the visitor agrees. Provided by Google for YouTube (terms, privacy policy) and Google Maps (terms, privacy policy), and by Vimeo (terms, privacy policy).

Screenshots

Blocks

This plugin provides 1 block.

  • Privacy settings link A link that opens the cookie preferences again.

Installation

  1. Install and activate the plugin. YouTube, Vimeo and Google Maps embeds are blocked from now on.
  2. Go to Settings › Silvertrail, turn on the trackers the site uses and enter their IDs.

Developers set everything else in code with the silvertrail_settings and silvertrail_config filters. The README, on GitHub and in the plugin folder, is the complete reference.

FAQ

How do I add a service in code?

Register it on the silvertrail_register action:

add_action( 'silvertrail_register', function () {
    silvertrail_register_service( 'hubspot', array(
        'group'       => 'marketing',
        'name'        => 'HubSpot',
        'provider'    => 'HubSpot, Inc.',
        'purpose'     => 'Tracks form conversions.',
        'privacy_url' => 'https://legal.hubspot.com/privacy-policy',
        'hosts'       => array( 'js.hs-scripts.com' ),
        'handles'     => array( 'hubspot-tracking' ),
    ) );
} );

The groups are essential, preferences, statistics, marketing and external-media. silvertrail_register_group() adds another one, and the silvertrail_config filter edits or removes anything at the end. Keep the config the same on every request, because Silvertrail asks every visitor again when the set of services changes.

How do I change or turn on a preset in code?

Register its ID again with only the fields to change. A preset’s ID turns it on with its defaults:

add_action( 'silvertrail_register', function () {
    silvertrail_register_service( 'google-tag-manager', array( 'tag_id' => 'GTM-XXXXXXX' ) );
    silvertrail_register_service( 'youtube', array( 'cookies' => 'VISITOR_INFO1_LIVE, YSC' ) );
} );

To remove a service, even one turned on in the settings, unset it in the silvertrail_config filter. The settings page marks each preset that code turned on, changed or removed.

How do I block a script in my theme?

Give it the type text/plain and the service ID:

<script type="text/plain" data-silvertrail="hubspot" src="https://js.hs-scripts.com/123.js"></script>

The browser ignores the tag until the visitor agrees to hubspot.

How do I show no banner to some visitors, for example by country?

Listen for the silvertrail:before-prompt event and answer with a promise that resolves to prompt, accept-all or reject-all:

window.addEventListener( 'silvertrail:before-prompt', ( event ) => {
    event.detail.respondWith( fetch( '/my-region-check' ).then( ( r ) => r.text() ) );
} );

The answer must arrive within three seconds, otherwise the banner opens.

How do I read the choice?

In the browser, window.silvertrail.has( 'hubspot' ) returns the choice, and the silvertrail:change event fires after every decision. In PHP, silvertrail_has( 'hubspot' ) reads the cookie, which only works on requests a page cache never serves, such as form posts.

Can I change the look?

The banner takes its colours, corners and buttons from the theme’s theme.json. The appearance that matches the theme keeps its colours as they are, and the other one puts the theme’s lightest or darkest colour in the background. Themes without a theme.json get Silvertrail’s own light or dark colours. In code, the silvertrail_design filter sets any colour, the corner radius and the button padding and weight.

For anything else, add silvertrail/silvertrail.css to your theme. Silvertrail loads it after its own styles. The docs/styling.md file in the plugin folder is a brief for an AI assistant that writes this stylesheet, and Settings › Silvertrail › Banner › Custom styles copies it together with your theme’s colours and fonts.

You can also turn off the default styles with load_css in the silvertrail_settings filter, or copy templates/banner.php into your theme as silvertrail/banner.php and change the markup while keeping the data-silvertrail-* attributes.

How do I change the texts?

Under Settings › Silvertrail › Banner, every text of the site language is one JSON object. Change the text in quotes after the colon and save, or paste a whole set. Delete a line to bring back its default text.

A developer can put the same JSON into the theme as silvertrail/texts-de_CH.json for one language, or silvertrail/texts.json for every language. A child theme wins over its parent. From a plugin, return another path or an array in the silvertrail_translation filter:

add_filter( 'silvertrail_translation', function ( $translation, $locale ) {
    return __DIR__ . "/texts/{$locale}.json";
}, 10, 2 );

The admin’s edits win over the file, and the silvertrail_texts filter runs last. wp silvertrail validate reports unknown keys and broken files.

Can I set the settings in code?

Yes, every one of them, with the silvertrail_settings filter. The settings page then shows the field as set in code:

add_filter( 'silvertrail_settings', function ( $settings ) {
    $settings['expiry_months'] = 12;
    return $settings;
} );

wp silvertrail settings lists every value and where it comes from.

Can I set it up before visitors see it?

Yes. Switch Silvertrail off at the top of Settings › Silvertrail. It then adds nothing to the site: no banner, no blocking, none of its tags. Add ?silvertrail-preview to any URL to see that page as visitors will get it, and switch Silvertrail on when everything fits.

I changed the services or asked everyone again, and nothing happened. Why?

Cached pages still carry the old version of the settings. Purge the page cache after changing services or after pressing «Ask everyone again», and visitors are asked on their next page view.

Does it work without a footer link?

Yes, with the floating button. It is off by default. Under Settings › Silvertrail › Banner › Look, pick the bottom left or right corner, and it reopens the preferences on every page without a link to #silvertrail. Without it, put the Privacy settings link block or the [silvertrail_link] shortcode in the footer. The silvertrail_reopen_icon filter swaps its icon, and the theme’s silvertrail/silvertrail.css styles it through .silvertrail-reopen.

Reviews

There are no reviews for this plugin.

Contributors & Developers

“Silvertrail” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Silvertrail” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.0.0

  • First release.