WP Manifestindependent plugin directory
manifest / i18n / polylang-toolkit

Polylang Toolkit

Battle-tested helpers and fixes for multilingual WordPress sites running Polylang

by Oleksii Kyievskyi · github.com/kyievskyi88/polylang-toolkit · website

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/kyievskyi88/polylang-toolkit/archive/refs/heads/main.zip

Readme

Polylang Toolkit

A small WordPress plugin with battle-tested helpers and fixes for multilingual sites running Polylang. Every piece of it was extracted from problems I actually hit (and solved) on production multilingual WordPress projects — nothing speculative, no framework ambitions.

What's inside

1. Language-aware template helpers (includes/helpers.php)

Helper Problem it solves
plltk_home_url( $lang = '' ) A hardcoded home_url('/') in the theme always points at the default-language front page, so the logo link "drops" visitors out of their language.
plltk_get_term_by_slug( $slug, $taxonomy, $lang = '' ) get_term_by( 'slug', … ) returns the term of whatever language owns that slug — templates that look terms up by a known slug break on translated pages. This resolves the term, then translates it to the target language.
plltk_count_posts( $post_type, $lang = '' ) wp_count_posts() is language-blind: on an EN + UK site it reports the total across all languages, breaking "N items" counters on translated archives.

All helpers degrade gracefully — with Polylang inactive they fall back to core behaviour instead of fataling.

2. Regional .mo fallback (class-mofile-fallback.php)

Your theme ships uk.mo, but WordPress runs the uk_UA locale (or the other way round) — translations silently don't load and the site shows source strings. Instead of renaming files on every deploy, the plugin retries the sibling variant when the requested file is missing:

requested uk_UA.mo, missing → tries uk.mo
requested uk.mo,    missing → tries uk_XX.mo found on disk

3. Translated front page canonical guard (class-frontpage-canonical-guard.php)

With a static front page and its translation assigned, the clean language root (/uk/) can 301-redirect to the translated page slug (/uk/holovna/). The language root is the URL you put in menus, sitemaps and ads — the slug URL duplicates it and leaks into search indexes. The guard suppresses that canonical redirect exactly on the translated front page and nowhere else.

Opt out any time:

add_filter( 'plltk_guard_translated_frontpage', '__return_false' );

Requirements

  • WordPress 6.0+
  • PHP 7.4+
  • Polylang (free or Pro). Without it the plugin stays dormant and shows a single admin notice.

Installation

  1. Download or clone into wp-content/plugins/polylang-toolkit.
  2. Activate Polylang Toolkit in the admin.
  3. Use the helpers in your theme; the two fixes work automatically.

Philosophy

Small, readable, hook-based. No options page, no autoloader, no build step — a plugin you can audit in five minutes. Behaviour is controlled with WordPress filters, the way it should be.

License

GPL-2.0-or-later. See LICENSE.

Author

Oleksii Kyievskyi — WordPress / PHP developer, 14+ years of custom themes, plugins and multilingual builds. Telegram: t.me/DevCode_Man

Read the full README on GitHub →