WDD Polylang Floating Language Switcher

A floating, mobile-first language switcher widget for Polylang-powered WordPress sites.

Version: 1.0.0 Requires: WordPress 5.0+, PHP 7.4+ Dependency: Polylang

Overview

This plugin renders a fixed-position button in the corner of the screen. Tapping it opens a dropdown listing every language configured in Polylang, with flags and language names. It's designed primarily for mobile visitors, though desktop visibility can be turned on in settings.

Everything the widget needs — markup, styles, and behaviour — is self-contained under a single element, #wdd-lang-switcher, so it can be dropped into any theme without affecting existing layouts or styles.

Installation

  1. Make sure Polylang is installed and active, with at least two languages configured.
  2. Upload the plugin folder to /wp-content/plugins/, or install the zip via Plugins → Add New → Upload Plugin.
  3. Activate WDD Polylang Floating Language Switcher from the Plugins screen.
  4. Go to Settings → Lang Switcher to configure position, colors, and visibility.

The widget renders automatically on the front end once Polylang is detected — no shortcode or template tag is needed.

Settings

All settings live under Settings → Lang Switcher in wp-admin.

SettingDefaultDescription
PositionrightWhich corner the widget anchors to — left or right.
Bottom offset24pxDistance from the bottom edge of the screen.
Side offset20pxDistance from the chosen side edge.
Background color#1a1a1aToggle button background.
Text color#ffffffToggle button text and icon color.
Breakpoint767pxThe dividing line between "mobile" and "desktop" for the two visibility toggles below.
Show on mobileOnDisplay the widget at or below the breakpoint.
Show on desktopOffDisplay the widget above the breakpoint.
Show flagsOnShow flag images next to each language in the dropdown.
Show namesOnShow full language names instead of just the slug.
Show globe iconOnShow a globe icon on the toggle button.
Button labelEmptyCustom text for the button. Leave empty to show the current language slug (e.g. EN).
Hide current languageOffRemove the active language from the dropdown list, since it's already shown on the button.
Border radius50pxRoundness of the toggle button. 50 gives a pill shape, 0 gives square corners.

Mobile and desktop visibility are independent — both, either, or neither can be enabled at once.

How it works

Rendering

The widget HTML is printed in wp_footer. It pulls the active language list directly from Polylang's pll_the_languages() function — there's no caching layer of its own, so changes made in Polylang's language settings appear immediately.

Styling

Static, unchanging styles (layout, animation, hover states) live in a regular stylesheet. Settings that the admin can change — colors, position, offsets, border radius — are compiled into a small inline <style> block and printed in wp_footer as well, just before the widget markup. Printing styles in the footer, after every other stylesheet on the page, is what lets the widget's own design settings consistently take priority over page builder and theme styles without needing a long list of overrides.

Behavior

A small vanilla JavaScript file (no jQuery) handles opening and closing the dropdown: click the button to toggle it, click outside or press Esc to close it, and clicking any language link closes it before navigating.

Assets

Both the CSS and JS ship in two versions — a readable source file and a minified one. The minified versions load by default. Add this to wp-config.php to load the readable source files instead, useful when debugging:

define( 'SCRIPT_DEBUG', true );

File structure

wdd-polylang-floating-switcher/ ├── wdd-polylang-floating-switcher.php Main plugin file — constants, activation hooks ├── readme.txt ├── admin/ │ └── class-wdd-pls-settings.php Settings page under Settings → Lang Switcher ├── assets/ │ ├── css/ │ │ ├── wdd-pls-style.css Static styles (readable source) │ │ └── wdd-pls-style.min.css Static styles (production) │ └── js/ │ ├── wdd-pls-script.js Frontend behavior (readable source) │ ├── wdd-pls-script.min.js Frontend behavior (production) │ └── wdd-pls-admin.js Color picker init, admin screen only └── includes/ └── class-wdd-polylang-switcher.php Core class — rendering, dynamic CSS, enqueue

Theme & plugin compatibility

Every CSS rule the plugin outputs is scoped under the widget's wrapper element, #wdd-lang-switcher, so it cannot affect any other element on the page — and nothing on the page can leak in and affect the widget either, beyond what's noted below.

Specifically tested against:

Also expected to work cleanly with Astra, Divi, GeneratePress, OceanWP, and Avada, since the same scoping approach applies regardless of theme.

WP Rocket — "Delay JavaScript Execution" If this WP Rocket setting is enabled, the very first tap on the toggle button can be consumed by WP Rocket's delay mechanism before the plugin's own click listener has attached, so the dropdown won't open on that first tap. If you're using this feature, exclude the plugin's script handle (wdd-pls-script) from delay execution, either through WP Rocket's exclusion field in Settings → WP Rocket → File Optimization, or by disabling Delay JS Execution for this page if site-wide exclusion isn't an option.

Troubleshooting

Widget doesn't appear at all

Dropdown doesn't open on click

Colors or position look wrong

FAQ

Does this work without Polylang?

No — the plugin checks for Polylang on every load and renders nothing if it isn't active.

Can I show it on both mobile and desktop?

Yes, enable both toggles in settings. They're independent of each other.

Will it conflict with my theme's existing language switcher?

No — this widget doesn't replace or hook into any existing switcher; it simply adds its own floating element to the page. If you have another switcher already, you may want to disable one to avoid showing the same control twice.