Automatically replaces internal links with their translated versions on page load for WordPress sites using Polylang.
When you have a multilingual WordPress site with Polylang, internal links in your content may still point to the original language version. This plugin automatically detects and replaces these links with their translated equivalents based on the current language.
- Automatic link replacement - Replaces internal links on-the-fly during page render
- Multiple content types - Works with post content, navigation menus, and Elementor pages
- Smart detection - Uses WordPress rewrite rules for accurate URL resolution
- Preserves URL components - Keeps query parameters and URL fragments intact
- Language switcher aware - Skips links with
hreflangorlangattributes - WooCommerce compatible - Excludes account pages to prevent redirect issues
- Post and page content (
the_contentfilter) - Navigation menus (
wp_nav_menu_itemsfilter) - Elementor frontend content (
elementor/frontend/the_contentfilter)
- WordPress 6.0 or higher
- PHP 8.1 or higher
- Polylang (free or Pro)
composer require epic-wp/polylang-internal-link-replacer- Download or clone this repository into your
wp-content/plugins/directory - Run
composer installin the plugin directory - Activate the plugin in WordPress admin
cd wp-content/plugins
git clone https://github.com/epicwp/polylang-internal-link-replacer.git
cd polylang-internal-link-replacer
composer installOnce activated, the plugin works automatically. No configuration needed.
The plugin runs on the frontend only and replaces internal links based on the current language set by Polylang.
This plugin works great as a companion to Polylang Automatic AI Translation - our AI-powered translation plugin for Polylang.
The AI translation plugin already translates internal links during the translation process using intelligent link detection. However, in some edge cases, links may not be found or translated:
- Links added after initial translation
- Dynamic links generated by shortcodes or plugins
- Links in cached content
- Complex URL structures
Polylang Internal Link Replacer serves as a safety net, catching any internal links that weren't translated and replacing them on page load. This ensures your visitors always land on content in their preferred language.
- When a page loads, the plugin scans the HTML content for internal links
- Each link URL is parsed using WordPress rewrite rules to identify the target post or term
- The plugin queries Polylang for the translated version in the current language
- If a translation exists, the link is replaced with the translated URL
The plugin is optimized for performance:
- Only runs on frontend requests
- Skips processing if no
hrefattributes are found - Uses efficient DOM parsing with voku/simple_html_dom
- Caches rewrite rules during request
GPL-2.0-or-later