=== Add as Preferred Source on Google ===
Contributors: mathewt
Donate link: https://seoactionplan.com/extdonate
Tags: google preferred source, add as trusted source, google trusted source, google search, preferred news source
Requires at least: 5.0
Tested up to: 7.0
Stable tag: 1.2.3
Requires PHP: 7.2
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Display a banner that allows users to add your website as a preferred source on Google Search.

== Description ==

Add as Preferred Source on Google plugin displays a banner and inline button on your website that directs visitors to Google's preferred sources feature. When clicked, the banner takes users to Google's preferences page where they can add your site as a preferred source for their personalized search results.

**What it does:**

* Displays a customizable banner on your website
* Links to Google's preferred sources feature
* Allows users to set your site as a preferred source in their Google Search settings
* Provides banner customization options (colors, text, position)
* Includes device-specific display controls for the banner (show it on mobile, desktop, or both)
* Controls exactly where the banner appears with Display Rules (all pages, posts only, pages only, or front page only)
* Excludes specific categories or individual posts/pages from showing the banner
* Triggers the banner immediately on page load, after the visitor scrolls a set percentage, or after a time delay
* Controls what happens after a visitor closes the banner - hide it for a configurable number of days, or show it again on every page view
* Tracks impressions, clicks, and dismissals with a built-in 30-day analytics dashboard
* **Localized Google badge** - the official badge ships in 17 languages, with an Auto mode that matches your site language
* **Dark and Light badge themes** - pick the badge variant that best fits your design
* **Custom text badge** - type your own button label for any language not in the built-in list; the badge renders with the Google logo in the same style as the official badges
* **Inline badge style switcher** - choose between the full card layout (title, subtitle, badge) or a clean simple style that shows only the badge
* Inline button with its own position (above content, below content, or both), post type targeting, color pickers, and customizable title and subtitle
* Automatically clears page caches from popular caching plugins when you save settings, so changes go live immediately

**About Google Preferred Sources:**

Google's preferred sources is a feature that allows users to indicate which sources they want to see more of in their search results. This is a Google feature, not affiliated with this plugin. Users who add your site as a preferred source may see your content more frequently in their personalized search results.

**DISCLAIMER:** This plugin is not associated with Google and was created to help website owners make a banner and inline card for adding their sites to Google's Preferred Source. The term "Google" is used solely to convey the plugin's function, and we are not related to Google in any way.

Thank you for using the Add as Preferred Source plugin :) If you like it, please leave a [★★★★★ rating](https://wordpress.org/support/plugin/add-as-preferred-source/reviews/#new-post) to support us on WordPress.org to help us spread the word to the community.

**Plugin Features:**

* Custom domain override for the Google Preferred Source link
* Customizable banner text with website name variable
* Color customization for background and text
* Position control (top or bottom of page)
* Device-specific display for the banner (mobile, desktop, or both) - the inline button is not affected by these settings and appears on all devices
* Cookie-based dismissal with a configurable hide duration (1-365 days, default 7), or switch to showing the banner again on every page view
* Responsive design
* Translation ready
* **Display Rules** - show the banner everywhere, on posts only, pages only, or the front page only; exclude specific categories or individual post/page IDs
* **Display Trigger** - show immediately on page load, after the visitor scrolls a configurable percentage of the page (10-90%), or after a set time delay (1-60 seconds)
* **Click-Through Analytics Dashboard** - view 30-day impressions, clicks, dismissals, and click rate with a visual bar chart directly in the admin
* **Badge Language** - choose from 17 official badge languages (Danish, German, Spanish, Estonian, Finnish, French, Hindi, Hebrew, Japanese, Korean, Norwegian, Brazilian Portuguese, Russian, Swedish, Turkish, Ukrainian, and English), or leave it on "Auto" to match your site language
* **Badge Theme** - switch between the Dark (default) and Light versions of the official Google badge, with a live preview in the settings
* **Custom Badge Text** - type your own button label for any language not in the built-in list; the badge renders with the Google "G" logo matching the official badge style
* **Inline Button** - an in-content card with its own enable toggle, position (above content, below content, or both), post type targeting (posts, pages, and custom post types), background and text color pickers, and customizable title and subtitle
* **Inline Badge Style** - switch the inline button between "Default" (full card with title and subtitle) and "Simple" (badge image only, no card)
* **Automatic Cache Clearing** - saving settings purges page caches from popular caching plugins (WP Rocket, W3 Total Cache, WP Super Cache, LiteSpeed Cache, and more) so changes go live immediately
* **Lightweight and Accessible** - CSS and JavaScript load only on pages that actually show the banner or button, assets are minified, and the banner is fully keyboard accessible

**Technical Requirements:**

* WordPress 5.0 or higher
* PHP 7.2 or higher
* Modern web browser with JavaScript enabled

== Installation ==

**Automatic Installation:**
1. Log in to your WordPress admin dashboard
2. Go to Plugins > Add New
3. Search for "Add as Preferred Source"
4. Click "Install Now" and then "Activate"
5. Go to Settings > Add as Preferred Source to configure

**Manual Installation:**
1. Download the plugin zip file
2. Upload via Plugins > Add New > Upload Plugin
3. Activate the plugin
4. Go to Settings > Add as Preferred Source to configure

**Configuration:**
1. Enable the banner in plugin settings
2. Customize banner text and colors
3. Choose display position and device settings
4. Save settings

== Configuration ==

After installation, go to **Settings > Add as Preferred Source** in your WordPress admin to configure the plugin.

**Step 1: Basic Settings**

* **Enable Banner:** Check this box to activate the banner on your website. The banner will not appear until this is enabled.

* **Website Name:** Enter your website or publication name. This defaults to your WordPress site title but can be customized. This name will replace the {website_name} placeholder in your banner text.

* **Custom Domain:** Override the URL used in the Google Preferred Source link. Leave this empty to use your site's domain automatically (recommended). Only set this if the link should point to a different URL - for example, if your WordPress site lives on a subdomain but your canonical domain is `https://example.com`.

* **Banner Text:** Customize the message displayed to visitors. Default text is "Add as a preferred source on Google". You can use the placeholder {website_name} anywhere in your text, and it will be automatically replaced with the website name you specified above.
  - Example: "Add {website_name} as your preferred source on Google"
  - Example: "Get more content from {website_name} - add us as a preferred source"

* **Badge Language:** Choose which language to use for the Google badge image. "Auto" detects your site's language automatically and falls back to English if the language is not available. 17 languages are included: Danish, German, Spanish, Estonian, Finnish, French, Hindi, Hebrew, Japanese, Korean, Norwegian, Brazilian Portuguese, Russian, Swedish, Turkish, Ukrainian, and English. **If your language is not listed, select "Custom text (my language is not listed)"** - this lets you type your own button label, and a badge will be generated with the Google logo and your text, styled to match the official badges.

* **Badge Theme:** Choose between the Dark (default) and Light versions of the badge. Dark works best on light-colored banner backgrounds; Light works best on dark-colored backgrounds.

* **Banner Position:** Choose where the banner appears on your website:
  - **Top:** Banner appears at the top of the page, above all content
  - **Bottom:** Banner appears at the bottom of the page (recommended for better user experience)

* **After Visitor Closes Banner:** Decide what happens when a visitor clicks the close (x) button:
  - **Hide it for a number of days (uses a cookie):** The banner stays hidden for the duration you set in the **Hide Duration (days)** field (1-365 days, default 7). This matches the behaviour of earlier versions and remains the default for sites updating from an older version.
  - **Show it again on every page view (ignores the cookie):** Closing the banner only hides it for the current page. It appears again on the next page view, wherever your Display Rules allow it. This is the default for new installs.

**Step 2: Appearance Customization**

* **Banner Background Color:** Click the color picker to choose a background color that matches your website design. Default is dark gray (#1a1a1a).

* **Text Color:** Select the color for the banner text and close button. Ensure good contrast with your background color for readability. Default is white (#ffffff).

**Step 3: Display Options**

* **Show on Mobile:** Check this box to display the banner on mobile devices (phones and tablets).

* **Show on Desktop:** Check this box to display the banner on desktop computers and laptops.

You can enable both, or choose to show the banner only on specific device types based on your audience preferences.

**Notes on device detection:**

* These settings apply to the banner only. The inline button appears on all devices regardless of these checkboxes.
* Device detection is user-agent based (WordPress's `wp_is_mobile()` function), so tablets are treated as mobile devices.
* On sites with full-page caching, a cached page may have been generated for a different device type, so the banner can occasionally appear or stay hidden on the "wrong" device until the cache refreshes.

**Step 4: Save and Test**

1. Click **Save Changes** to apply your settings
2. Visit your website to see the banner in action
3. Click the banner to test the Google redirect functionality
4. Use the close (x) button to test the dismissal feature

**Testing Tips:**
* Clear your browser cache and any server/plugin caches after making changes
* Test in incognito/private browsing mode to see the banner fresh
* Add a parameter to your URL (e.g., ?test=1) to bypass cache
* Check on different devices based on your display settings
* The banner will stay hidden after a user closes it for the number of days you set (7 by default), unless you choose the "every page view" option

**Preview Feature:**
The settings page includes a live preview that updates as you modify colors, text, and position. This helps you see how the banner will look before saving changes.

**Step 5: Display Trigger**

Control when the banner appears to a visitor:

* **Immediately on page load** - the banner shows as soon as the page finishes loading (default behaviour).
* **After user scrolls** - the banner only appears once the visitor has scrolled a set percentage of the page. You can choose any value between 10% and 90% in 5% increments. Useful for keeping the banner out of the way until the reader is engaged with your content.
* **After a time delay** - the banner waits a number of seconds (1-60) before appearing. This lets visitors settle in before the prompt is shown.

**Step 6: Display Rules**

Target exactly which pages show the banner:

* **Everywhere** - the banner appears on all pages and posts across your site (default).
* **Posts only** - restricts the banner to single post pages.
* **Pages only** - restricts the banner to static WordPress pages.
* **Front page only** - shows the banner exclusively on your site's home/front page.

You can further refine visibility with two exclusion options:

* **Exclude Categories** - search for and select any categories whose posts should never show the banner. The picker supports live search so you can find categories quickly without loading a long list.
* **Exclude Post/Page IDs** - enter a comma-separated list of post or page IDs to suppress the banner on specific pieces of content.

**Step 7: Analytics Dashboard**

Open the **Analytics** tab on the settings page to view banner performance over the last 30 days:

* **Impressions** - how many times the banner was displayed to visitors.
* **Clicks** - how many visitors clicked through to the Google preferences page.
* **Dismissals** - how many visitors closed the banner without clicking.
* **Click Rate** - the percentage of impressions that resulted in a click (clicks / impressions).

A colour-coded bar chart shows the daily breakdown of all three metrics so you can spot trends at a glance. Data is stored locally in your WordPress database and requires no third-party services.

Note: the analytics dashboard only tracks the banner. Impressions and clicks on the inline button are not recorded yet - inline button tracking will be added in a future version.

**Step 8: Inline Button**

Open the **Inline Button** tab to configure the in-content card, which works independently of the banner:

* **Enable Inline Button** - turn the inline button on or off. It can run alongside the banner or on its own.
* **Badge Style** - choose "Default" (a card with title, subtitle, and badge) or "Simple" (the badge image only, with no card around it). Selecting Simple hides the card-specific fields below.
* **Button Position** - show the button above your content, below it, or in both places.
* **Post Types** - select which post types display the button: posts, pages, and any public custom post types registered on your site.
* **Background Color / Text Color** - use the color pickers to match the card to your site design.
* **Inline Title** - the main heading shown on the card.
* **Inline Subtitle** - the supporting text displayed below the title.

A live preview on the tab updates as you change these settings, just like the banner preview.

== Frequently Asked Questions ==

= Is this plugin affiliated with Google? =

No. This plugin is not associated with Google. It was created to help website owners make a banner and inline card for adding their sites to Google's Preferred Source. The term "Google" is used solely to convey the plugin's function, and we are not related to Google in any way.

= What are Google preferred sources? =

Google preferred sources is a feature that lets users indicate which sources they prefer to see in their search results. This is a Google feature that affects individual users' personalized search results.

= Does this guarantee better search rankings? =

No. This plugin only provides a way for users to access Google's preferred sources feature. It does not guarantee improved search rankings or visibility.

= How does the banner work? =

The banner displays on your website according to your settings. When clicked, it opens Google's preferences page where users can add your site as a preferred source.

= What if my site is not showing on Google's preferences page? =

The plugin only opens Google's preferred sources page with your domain pre-filled - whether your site can actually be selected there is decided entirely by Google. If your site does not appear, check the following:

1. **Verify the domain the plugin is sending.** If you use the Custom Domain setting, make sure it exactly matches your site's canonical domain (including the correct subdomain, such as www). Leave it empty to use your site's domain automatically.
2. **Make sure your site is indexed by Google.** Search for `site:yourdomain.com` on Google. If nothing appears, your site is not indexed yet - set up [Google Search Console](https://search.google.com/search-console) and submit your sitemap.
3. **Check feature availability in your region.** Google's preferred sources feature is only available in certain countries and languages, so some visitors may not be able to use it even when your site is eligible.
4. **Sign in to a Google account.** Visitors must be signed in to Google for the preferences page to work.
5. **Be patient with newer sites.** Google generally surfaces established, regularly publishing sites in this feature. If your site is new or rarely indexed in Google's news surfaces, it may take time before it becomes selectable.

If your site is indexed and the domain is correct but it still cannot be added, the limitation is on Google's side - there is unfortunately nothing the plugin can change about that.

= Can I customize the banner appearance? =

Yes. You can customize the text, colors, position, and choose which devices display the banner.

= How long does the banner stay hidden after someone closes it? =

That depends on the "After Visitor Closes Banner" setting. New installs show the banner again on every page view, so closing it only hides it for the current page and no dismissal cookie is stored. Sites that updated from an older version keep the cookie-based behaviour: the banner stays hidden for 7 days by default, and you can change this duration to anything between 1 and 365 days.

= Will this affect my website's performance? =

The plugin uses minimal resources and should not significantly impact website performance.

= Does the plugin send any data to external services? =

The banner, inline button, and analytics features run entirely on your site - no visitor data ever leaves your WordPress database.

= Can I translate the plugin? =

Yes, the plugin is translation ready and follows WordPress internationalization standards.

= Does the plugin work with all themes? =

The plugin is designed to work with most WordPress themes. If you experience display issues, check for theme conflicts or contact support.

= Why does the banner show (or not show) on the wrong device? =

Device detection is based on the visitor's user agent, so tablets are treated as mobile devices. Also note that the "Show on Mobile" and "Show on Desktop" settings apply to the banner only - the inline button appears on all devices. If you use a full-page caching plugin, a page cached for one device type may be served to another, which can make the banner appear or stay hidden on the wrong device until the cache refreshes. Caching plugins that support separate mobile caches avoid this.

= What should I do if the banner doesn't appear? =

1. Ensure the banner is enabled in settings
2. Check device display settings match your current device
3. Clear all browser and server caches
4. Test in incognito/private browsing mode
5. Verify there are no JavaScript errors in browser console

= Can I use this on multiple websites? =

Yes, you can install this plugin on multiple WordPress sites. Each installation has separate settings.

== Screenshots ==

1. Plugin settings page with customization options and live preview
2. Banner display on website frontend as top
3. Inline button card settings page with customization options and live preview
4. Inline button display on website frontend
5. Analytics page showing the impressions, clicks, dismissals, and click-through rate over 30 days

== Changelog ==

= 1.2.3 =
* New: Badge Theme setting - choose between the Dark (default) and Light versions of the official Google badge. The light badge works best on dark backgrounds.
* New: Light badge images added for all 17 supported languages, with live preview in the settings page when switching theme or language.
* New: "After Visitor Closes Banner" setting - control what happens when a visitor dismisses the banner. Keep the cookie-based behaviour with a configurable hide duration (1-365 days), or show the banner again on every page view.
* New: "Hide Duration (days)" setting - the dismissal period is no longer fixed at 7 days; choose any duration between 1 and 365 days.
* Performance: Analytics impressions are now counted once per visitor per day instead of on every page view, dramatically reducing server requests on busy sites. Clicks and dismissals are still tracked every time.
* Performance: Tracking requests now use sendBeacon, so they never delay page rendering or the click-through to Google.
* Performance: Banner CSS and JavaScript only load on pages where the banner or inline button will actually appear, respecting Display Rules, device settings, and inline post type selections.
* Performance: Admin code is no longer loaded on front-end requests.
* Performance: Front-end CSS and JavaScript are now served minified (about 50% smaller).
* Fix: The inline button card no longer stretches across the full screen width on pages built with Elementor - it is now capped at a readable width and centered.
You can consider a domation to support the project and new features.

= 1.2.2 =
* New: Localized Google badge support - the "Add as Preferred Source on Google" button now displays in the site's default language automatically based on the site locale.
* New: Badge Language setting in Banner Settings - choose from 17 supported languages (Danish, German, Spanish, Estonian, Finnish, French, Hindi, Hebrew, Japanese, Korean, Norwegian, Brazilian Portuguese, Russian, Swedish, Turkish, Ukrainian, and English) or leave it on "Auto" to match your site language.
* Improvement: More languages will be added with each update! Stay tuned!
* New: Custom text badge - select "Custom text (my language is not listed)" in the Badge Language setting and type your own button label. The badge renders with the Google "G" logo and your text, styled to match the official badge, so any language is supported.
* New: Inline badge style switcher - a new "Badge Style" setting in the Inline Button tab lets you choose between "Default" (full card with title and subtitle) and "Simple" (badge image only, no card). The Simple style hides the card-specific fields in the admin and shows only the badge on the frontend.

= 1.2.1 =
* New: Custom Domain setting - override the domain used in the Google Preferred Source link based on your preference.

= 1.2 =
* New: Analytics dashboard added - track impressions, clicks, dismissals, and click-through rate over 30 days.
* New: Display Rules - restrict the banner to posts only, pages only, or front page only; exclude specific categories or post/page IDs.
* New: Display Trigger - show the banner immediately on page load, after the visitor scrolls a configurable percentage, or after a time delay.
* Improvement: Public-facing JavaScript rewritten in vanilla JS - jQuery dependency removed, script loads in footer.
* Improvement: Banner is now keyboard-accessible (`role="button"`, `tabindex="0"`, `Enter`/`Space` key support).
* Improvement: Close button selector scoped to the banner element to avoid conflicts with other plugins or themes.

= 1.1 =
* New: Refactored Inline Button with a modern card design.
* New: Added "Post Types" selection for inline button (replacing Content Type).
* New: Added Background and Text Color pickers for the inline button.
* New: Added "Inline Subtitle" option.
* Improvement: Inline button now uses standard Flexbox layout (Layout 2).
* Improvement: Fixed image display issues.
* Cleanup: Removed "Alignment" settings.

= 1.0.0 =
* Initial release
* Banner display functionality
* Customization options for text, colors, and position
* Device-specific display controls
* Cookie-based dismissal system
* Responsive design
* Translation support

== Upgrade Notice ==

= 1.0.1 =
Initial release of Add as Preferred Source plugin. Provides banner functionality to help users access Google's preferred sources feature.
