Skip to content

Allows you to use any menu item as a language switcher with Polylang. Add classes to menu items and the script handles the rest.

License

Notifications You must be signed in to change notification settings

The-Creative-Pixels/Manual-Polylang-Switcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Manual Polylang Switcher

A lightweight WordPress plugin that allows you to use any menu item as a language switcher with Polylang. No shortcodes required—just add CSS classes to your menu items and template parts, and the plugin handles the rest.


Features

  • Use any menu item as a language switcher.
  • Dynamically updates links to translated pages, posts, and taxonomy terms (categories, tags, etc.).
  • Show/hide template parts based on the current language.
  • Updates the placeholder text ("LAN" → "EN"/"ES") in navigation menus.

Installation

  1. Copy to wp-content/plugins/manual-polylang-switcher/.
  2. Activate the plugin.

Usage

1. Create a Language Switcher Menu

  1. In the WordPress Block Editor (Site Editor or Navigation block), create a Navigation block with a submenu.

  2. The parent menu item should display a placeholder: "LAN".

  3. Add child menu items for each language (e.g., "EN", "ES").

  4. Set the URL of each child to #.

  5. Add the following CSS classes to each menu item:

    • Parent: .lang-switcher
    • Child for English: .lang-btn lang-en
    • Child for Spanish: .lang-btn lang-es
    • Repeat for other languages.

The JavaScript will automatically update the # links to point to the correct translated URLs.


2. Create Language-Specific Template Parts

  1. Wrap blocks in a Group (or any container).

  2. Add the following CSS classes to each group:

    • English version: lang-part-en lang-hidden
    • Spanish version: lang-part-es lang-hidden
    • Repeat for other languages.
  3. Place these groups inside a template part (e.g., header, footer).

The plugin will automatically show only the group matching the current language.



Requirements

  • Polylang plugin must be active.
  • Works with FSE themes and block-based templates.

License

GPLv3 or later.

About

Allows you to use any menu item as a language switcher with Polylang. Add classes to menu items and the script handles the rest.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published