Pick your platform and mode.
Official popup, custom button or deeplink, across seven platform tabs from plain HTML to React.
Free SEO tool · Seven platforms covered
Configure Google's official Preferred Sources button, or a custom-styled one, and copy ready-to-paste code for WordPress, Elementor, Webflow, Shopify, Astro, React and plain HTML.
On WordPress? See Opace WordPress developmentUse the generator
Pick a platform and mode, style it, preview it live and copy exact snippets. Code generation runs entirely in your browser; your domain and label are never transmitted.
Preview only. The button is rendered by Google's script for this page's domain; on your site it will offer your domain. If the button doesn't render here, Google's script may not recognise this preview context; your embedded code is unaffected.
Google's preview didn't load (this can happen with ad blockers). Your generated code below is still correct.
▸ Paste inside your page's <head>:
<script async src="https://news.google.com/swg/js/v1/publisher.js"></script> ▸ Paste where you want the button to appear:
<div google-add-preferred-source-btn></div> Three things worth knowing before you ship it:
How the generator works
Every snippet uses only Google's documented API surface, assembled for the platform you actually publish on.
Official popup, custom button or deeplink, across seven platform tabs from plain HTML to React.
Themes, thirty languages and colour presets, previewed in a sandboxed frame before you commit.
Each block says exactly where it goes: head, template, widget, Liquid file or component.
The API surface comes straight from Google's official Preferred Sources documentation.
Which mode?
Auto mode
Two lines of code. Google's script renders its standard button where you place a div, and clicking it opens the add-source popup without the reader leaving your page. Quickest to ship and instantly recognisable, but Google controls the look.
Manual mode
The script's manual mode exposes exactly two methods, init and addPreferredSource, and your click handler calls the second. Choose this when the standard button clashes with your brand.
Deeplink fallback
No JavaScript, so it works in email newsletters, RSS footers and anywhere scripts are stripped, at the cost of sending readers to Google's page. Many publishers ship the popup on-site and the deeplink in their newsletter.
Honest by design
What this generator does, and deliberately does not do.
On WordPress?
Our free plugin ships the popup button, a Gutenberg block, a shortcode, a floating banner and GA4 click analytics, built by the Opace WordPress development team. The snippets this generator produces remain the manual alternative.
Generated for WordPress, auto mode
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_script( 'google-preferred-source',
'https://news.google.com/swg/js/v1/publisher.js',
array(), null,
array( 'strategy' => 'async' ) );
} );
✔ Then one Custom HTML block for the button The Preferred Sources suite
Everything you need to check eligibility, add the button and measure clicks, alongside the wider Opace tool catalogue.
Questions before you ship it
It's rendered by Google's own script (publisher.js). When a reader clicks it, a Google popup opens on your page letting them add your site as a preferred source in a couple of clicks, without leaving your article. It replaced the older approach of linking readers away to Google's preferences page.
Auto mode renders Google's standard button into a <div> you place. It's the quickest, but Google controls the look. Manual mode lets your own styled button trigger the same popup via Google's JavaScript API. The deeplink is a plain link to google.com/preferences/source?q=yourdomain.com with no JavaScript at all, so it works everywhere, including email newsletters, but it takes readers off your page.
Yes, and only the documented surface: Google's publisher.js script, the google-add-preferred-source-btn element with data-theme and data-lang, the manual-mode init() and addPreferredSource() methods, and the documented deeplink URL. Nothing proprietary, nothing undocumented.
Only partially, and honestly: Google's SDK provides no completion callback or event, so nobody can count confirmed adds. You can count clicks on the trigger by wrapping your own analytics event around the button click (our WordPress plugin does this with GA4 out of the box).
Not in your header, where it competes with primary CTAs and converts poorly. The high-performing spots are: immediately after your strongest insight within an article, the end of posts, and a persistent but quiet footer link.
Yes. Manual mode exists exactly for this: your button, any styling you like, and clicking it calls Google's addPreferredSource() which opens the same official popup.
Dozens. You set data-lang with an ISO code, or let it follow the reader's browser language. Google publishes the full supported list as a CSV linked from its Preferred Sources documentation.
No, the button confers no ranking benefit. Its job is persuasion: every reader who opts in sees more of your content in Top Stories, Discover and AI Overviews, and preferred users click through roughly twice as often per Google. Treat placement and wording as conversion optimisation.
Use the Plain HTML tab: the head script goes in your platform's "code injection" or head area and the button markup anywhere HTML is accepted. Framework packages (React, Vue, Svelte, Astro and more) are on our GitHub.
Created by Opace Digital Agency
Opace builds practical SEO and publishing systems from Birmingham for organisations across the UK and internationally, and this free suite comes from that client work.
Under a minute to working code
This tool is independently developed by Opace Digital Agency and is not affiliated with, endorsed by or sponsored by Google. Google and the Google logo are trademarks of Google LLC.