WPML Canonical Link
Reverts canonical posts to default language link for better SEO across multilingual sites
by Binjuhor · github.com/binjuhor/wpml-canonica-link · website
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/binjuhor/wpml-canonica-link/archive/refs/heads/main.zipReadme
WPML Canonical Link Plugin
A WordPress plugin that reverts canonical URLs to default language versions for better SEO across multilingual sites powered by WPML.
Description
This plugin automatically sets canonical URLs to point to the default language version of your content, helping to consolidate SEO authority and avoid duplicate content issues across different language versions of your multilingual WordPress site.
Features
- ✅ Selective Content Types: Choose which post types, taxonomies, and page types to apply canonical URL reversion
- ✅ WPML Integration: Seamlessly works with WPML multilingual functionality
- ✅ SEO Plugin Compatible: Works with Yoast SEO, RankMath, and other SEO plugins
- ✅ Smart Fallbacks: Gracefully handles missing translations
- ✅ Easy Configuration: Simple settings page in WordPress admin
- ✅ Safe Activation: Automatic dependency checking for WPML
- ✅ Comprehensive Coverage: Supports posts, pages, taxonomies, archives, and more
Requirements
- WordPress 5.0 or higher
- PHP 7.4 or higher
- WPML plugin (required dependency)
Installation
-
Download or clone this plugin to your WordPress plugins directory:
wp-content/plugins/wpml-canonica-link/ -
Activate the plugin through the WordPress admin interface or WP-CLI:
wp plugin activate wpml-canonica-link -
Configure the plugin settings at Settings → WPML Canonical Link
Configuration
Settings Page
Navigate to WordPress Admin → Settings → WPML Canonical Link to configure the plugin.
Available Options
Post Types
Select which post types should have their canonical URLs reverted to the default language:
- Posts
- Pages
- Custom Post Types
- Any publicly accessible post type
Taxonomies
Choose which taxonomies should point to default language versions:
- Categories
- Tags
- Custom Taxonomies
- Any publicly accessible taxonomy
Other Pages
Configure additional page types:
- Home Page: Site homepage/front page
- Author Archives: Author listing pages
- Date Archives: Date-based archive pages
Default Settings
The plugin automatically configures sensible defaults on first activation:
- Post Types: Posts and Pages ✅
- Taxonomies: Categories and Tags ✅
- Other Pages: Home Page ✅
How It Works
- Detection: Plugin detects when a visitor is viewing non-default language content
- Lookup: Finds the corresponding content in the default language using WPML functions
- Override: Replaces the canonical URL to point to the default language version
- Fallback: If no default language version exists, uses the current page URL
Example Behavior
Without Plugin:
<!-- On German version of a post -->
<link rel="canonical" href="https://example.com/de/sample-post/" />
With Plugin Active:
<!-- Same German post now points to English (default) version -->
<link rel="canonical" href="https://example.com/en/sample-post/" />
Technical Details
Hooks and Filters
The plugin hooks into these WordPress and SEO plugin filters:
wpseo_canonical(Yoast SEO)rel_canonical(WordPress core)wp_head(WordPress core)
WPML Integration
Uses official WPML filters and functions:
wpml_current_languagewpml_default_languagewpml_object_idwpml_home_url
Performance Considerations
- Lightweight implementation with minimal database queries
- Only activates on non-default language pages
- Efficient caching of language and object lookups
- No impact on admin or non-public pages
Compatibility
SEO Plugins
- ✅ Yoast SEO
- ✅ RankMath
- ✅ All in One SEO
- ✅ WordPress core canonical
- ✅ Custom canonical implementations
Page Builders
- ✅ Elementor
- ✅ Divi
- ✅ Gutenberg
- ✅ Classic Editor
- ✅ Any WordPress-compliant theme/builder
Troubleshooting
Plugin Not Working
- Ensure WPML is active and properly configured
- Check that you're viewing a non-default language page
- Verify content types are enabled in plugin settings
- Clear any caching plugins/systems
Canonical URL Not Changing
- Check if the content has a default language version
- Ensure the default language content is published
- Verify WPML translation connections
- Test with browser developer tools to view HTML source
Settings Not Saving
- Verify user has
manage_optionscapability - Check for JavaScript errors in browser console
- Ensure WordPress nonces are working properly
- Try deactivating other plugins temporarily
Development
File Structure
wpml-canonica-link/
├── wpml-canonical-link.php # Main plugin file
├── README.md # Documentation
└── languages/ # Translation files (future)
Key Functions
shouldOverrideCanonical()- Determines if canonical should be overriddengetDefaultLanguageCanonical()- Generates default language canonical URLisCurrentContentTypeEnabled()- Checks if current content type is enabled in settings
Extending the Plugin
You can extend functionality using WordPress hooks:
// Custom post types
add_filter('wpml_canonical_link_post_types', function($post_types) {
$post_types[] = 'my_custom_post_type';
return $post_types;
});
// Custom taxonomies
add_filter('wpml_canonical_link_taxonomies', function($taxonomies) {
$taxonomies[] = 'my_custom_taxonomy';
return $taxonomies;
});
Support
For issues, feature requests, or questions:
- Check the Troubleshooting section
- Review WPML documentation for translation setup
- Test with default WordPress theme to isolate conflicts
License
GPL v2 or later - same as WordPress core.
Changelog
Version 1.0.0
- Initial release
- Configurable post types and taxonomies
- Settings page interface
- WPML integration
- SEO plugin compatibility
- Comprehensive canonical URL handling
Contributing
Contributions are welcome! Please follow WordPress coding standards and test thoroughly with various WPML configurations.
Made with ❤️ for the WordPress multilingual community