Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/byteeater/preferred-source-in-google/archive/refs/heads/main.zipA lightweight WordPress plugin by Bloggerpi Digital that adds a clean, responsive “Add as a preferred source on Google” call to action to blog posts and/or pages. Choose Google's official interactive publisher button or a zero-JavaScript direct link.
Download the plugin
Official plugin information, updates and download page:
Download Preferred Source in Google from Bloggerpi Digital
Source code: GitHub repository
Latest source ZIP: Download repository source from GitHub (this is a source archive, not necessarily the tested release package).
For a ready-to-install version, use the provided plugin ZIP named preferred-source-in-google-v1.0.1.zip when published. A link to a landing page is not an assertion that the corresponding download endpoint already hosts the ZIP.
What does the plugin do?
Google Preferred Sources lets people tell Google which websites they would like to see more often in eligible Search experiences. This plugin adds a button to your content so visitors can conveniently choose your publication.
The feature influences users' personal search experiences. It does not guarantee rankings, traffic, eligibility or appearance in Search. The site must be available in Google's source preferences tool. Only domain-level or subdomain-level publications are eligible; subdirectory paths are not treated as separate publications.
Features
- Works automatically: No shortcode, template editing or Gutenberg blocks required.
- Flexible placement: Before content, after content, or both.
- Choose content types: Posts and pages independently. Defaults to posts only.
- Two modes: Official Google interactive button or lightweight HTML link.
- Responsive design: Default right-aligned desktop placement and left-aligned mobile layout (under 768px), without fixed positioning or global theme overrides.
- Official Google light/dark theme: Use Google's native widget styling.
- Direct-link customization: Domain override (hostname only) and editable text with
{Site Name}token. - Automatic hostname detection: Uses WordPress's configured home URL. A site installed under
/blog/uses the parent hostname. - Graceful fallback: Official mode shows a single CTA. The direct-link fallback is hidden while the native Google button loads, and appears after a brief delay only if Google does not render. A separate
noscriptlink covers JavaScript-disabled browsers. - Privacy conscious: No analytics, cookies or additional databases maintained by this plugin.
- Small footprint: No framework, npm install, Composer runtime or third-party analytics.
Screenshots / appearance
Layout is intentionally modest so that it fits most blog themes:
- Desktop: a compact CTA above the first paragraph, aligned to the right by default, like the Ahrefs example.
- Mobile: the same CTA follows the article container width and aligns left to prevent overflow.
- Official mode: Only one visible button: Google renders its native localized control; the fallback cannot overlap or duplicate it.
- Direct-link mode / fallback: a compact, legible HTML button with a small “G” mark and the site name.
The output is styled within .psig-cta and does not change your article title, body font, images, tables, breadcrumbs or metadata.
Install and activate
From a plugin ZIP
- Download the release ZIP (see Bloggerpi Digital downloads).
- In WordPress, open Plugins → Add New Plugin → Upload Plugin.
- Select the
.zipfile, choose Install Now, then Activate. - Open Settings → Preferred Source in Google.
- Select post types, placement, button mode, and alignment. Click Save Changes.
- Visit an individual published post to confirm that the CTA appears.
From GitHub source
- Download the source archive or clone
https://github.com/byteeater/preferred-source-in-google.git. - Make sure the root directory is named
preferred-source-in-googleand containspreferred-source-in-google.php. - Copy this directory into
wp-content/plugins/or ZIP the directory itself and use Upload Plugin. - Activate and configure it in WordPress.
Configuration reference
Navigate to Settings → Preferred Source in Google (WordPress administrator permission required).
| Setting | Possible values | Default | Notes |
|---|---|---|---|
| Enable button | On, Off | On | Off also prevents frontend asset loading. |
| Content types | Posts, Pages, both, neither | Posts | Only singular main-loop content; no archive cards. |
| Position | Before, After, Both | Before | Appends/prepends through the_content. |
| Button mode | Official Google, Direct link | Official | Google JS only loads in official mode. |
| Desktop alignment | Left, Center, Right | Right | Mobile is always left aligned for readability. |
| Official Google theme | Light, Dark | Light | Passed using data-theme; the official widget handles its text. |
| Direct-link domain override | Hostname | Auto-detected | Only applies to direct links; not Google's official widget. |
| Direct-link label | Text, {Site Name} token |
Auto-generated | Also used by official mode's fallback link. |
Direct-link URL example:
https://www.google.com/preferences/source?q=bloggerpi.com
For a site called My Blog, the default English link label is Add My Blog as a preferred source on Google. Indonesian site locale defaults to Tambahkan My Blog sebagai sumber pilihan di Google. Use a custom label when you prefer a shorter CTA. Google itself automatically localizes the official button.
Which mode should I use?
Official Google interactive button (recommended): Uses Google's documented publisher library (https://news.google.com/swg/js/v1/publisher.js), and renders <div google-add-preferred-source-btn data-theme="light"></div>. The control provides an interactive flow that can return readers to their article. The external script must be permitted by your browser/CSP. The direct-link fallback is initially hidden to avoid a double-button flash and appears after approximately three seconds if Google cannot render. The bridge detects widgets inside open or closed Shadow DOM; a noscript link is available for JavaScript-disabled browsers.
Direct link: A normal anchor to https://www.google.com/preferences/source?q=example.com. JavaScript is not required, and the link opens in a new tab. The reader confirms their choice on Google. Choose this mode for a minimal-dependency installation or strict script policy.
Where will the button appear?
It appears on an eligible is_singular() request, inside the main loop's rendered post content. It is not placed in archive listings, excerpts, feeds, REST API content or related-post side loops. A static homepage using a WordPress Page follows the Pages setting. Some page builders render content outside the_content/the main loop; they may need an integration that is beyond v1.0.
Theme and mobile compatibility
The plugin uses scoped CSS, max-width: 100%, normal document flow, and a minimum 44px direct-link target. At widths under 768px the wrapper is always left aligned. No global CSS selectors, fixed overlays, broad !important declarations, or floats are used. Theme CSS can still be unusually aggressive; test your own theme at mobile widths of 320px and 375px and on desktop.
The Google-rendered control's internals and final dimensions are owned by Google and may change independently of the plugin.
Privacy, security and performance
- No plugin-side collection of visitor information; no analytics, cookies, background AJAX or tracking pixel.
- In official mode, browsers request a Google-hosted script, which is a third-party dependency. Review your site's privacy statement, consent requirements and Content Security Policy as appropriate.
- The official script loads
asyncin the page head. On supported singular content, the plugin also loads its tiny frontend bridge and scoped stylesheet. - In direct mode, no plugin JavaScript is enqueued.
- Admin settings are limited to
manage_options; values are sanitized, output is escaped, and the WordPress Settings API handles option saving. - All options are kept in one
psig_settingsoption. No custom database tables or post modifications. - Deactivation keeps settings. Uninstallation deletes the plugin-owned option only.
Troubleshooting
No button appears
- Check that the global feature is enabled and the current content type is checked.
- Visit an individual post (not a category page or listing widget).
- Confirm WordPress Settings → General → Site Address (URL) has a valid hostname (or use a direct-link override).
- Clear the page cache/CDN cache and retry.
- Some page builders bypass WordPress's main-loop
the_contentfilter; this isn't supported in v1.0.
I only see a plain HTML link in official mode
The Google library may be blocked or may not render for your site. Verify that https://news.google.com/swg/js/v1/publisher.js isn't being blocked by an ad blocker, privacy software or CSP. Test your site in Google's source preferences tool. The visible fallback link is intentional.
The site is not selectable in Google
Google determines source eligibility. Use the Google source preferences tool, and refer to Google's publisher documentation. This plugin cannot register, verify, or force eligibility for a domain.
The official button looks different on my site
Google owns the official button's styling. The plugin only controls its wrapper alignment and spacing. Use the Direct link mode if you need a simpler, theme-neutral HTML button.
How can I change the wording?
Use the Direct-link button text setting. The Google-rendered button's wording is localized automatically by Google and isn't overridden by this setting.
Developer notes
- Entry point:
preferred-source-in-google.php. - Frontend and URL safety:
includes/class-psig-plugin.php. - WordPress settings:
includes/class-psig-settings.php. - Frontend styles:
assets/css/frontend.css. - Fallback detection:
assets/js/frontend.js. - Product requirements:
docs/PRD.md. - Functional smoke tests:
php tests/smoke.phpandnode tests/frontend.test.js(uses WordPress function stubs; not an integration test). - PHP syntax check:
find . -name '*.php' -print0 | xargs -0 -n1 php -l.
The plugin intentionally avoids writing into post content or modifying WordPress SEO plugin metadata. An independent smoke test suite runs without a full WordPress installation; use a staging WordPress environment for real browser/official-button behavior.
Changelog
1.0.1 — Single-button UI fix
- Prevent two buttons appearing together when Google renders in a Shadow DOM.
- Keep the fallback hidden during Google initialization, with a short delayed fallback only when needed.
- Add a
noscriptfallback for JavaScript-disabled clients. - Improve desktop/mobile spacing and reserve button height to reduce layout shift.
- Add regression tests for the fallback bridge.
1.0.0 — Initial release
- Frontend injection restricted to configured singular post types.
- Before, after, or dual content placement.
- Google interactive publisher widget with native light/dark theme.
- No-JavaScript direct-link option and direct-link fallback.
- Responsive, scoped styling with mobile alignment.
- Source hostname detection and validated override.
- WordPress Settings API and uninstall cleanup.
Credits and resources
Created and maintained by Bloggerpi Digital.
- Plugin landing and download page
- Google Search Central — Preferred Sources
- WordPress Plugin Developer Handbook
- WordPress
the_contenthook
License
GPL-2.0-or-later. See LICENSE.