WP Manifestindependent plugin directory
manifest / seo / wpml-canonica-link

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

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/binjuhor/wpml-canonica-link/archive/refs/heads/main.zip

Readme

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

  1. Download or clone this plugin to your WordPress plugins directory:

    wp-content/plugins/wpml-canonica-link/
  2. Activate the plugin through the WordPress admin interface or WP-CLI:

    wp plugin activate wpml-canonica-link
  3. 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

  1. Detection: Plugin detects when a visitor is viewing non-default language content
  2. Lookup: Finds the corresponding content in the default language using WPML functions
  3. Override: Replaces the canonical URL to point to the default language version
  4. 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_language
  • wpml_default_language
  • wpml_object_id
  • wpml_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

  1. Ensure WPML is active and properly configured
  2. Check that you're viewing a non-default language page
  3. Verify content types are enabled in plugin settings
  4. Clear any caching plugins/systems

Canonical URL Not Changing

  1. Check if the content has a default language version
  2. Ensure the default language content is published
  3. Verify WPML translation connections
  4. Test with browser developer tools to view HTML source

Settings Not Saving

  1. Verify user has manage_options capability
  2. Check for JavaScript errors in browser console
  3. Ensure WordPress nonces are working properly
  4. 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 overridden
  • getDefaultLanguageCanonical() - Generates default language canonical URL
  • isCurrentContentTypeEnabled() - 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:

  1. Check the Troubleshooting section
  2. Review WPML documentation for translation setup
  3. 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

Read the full README on GitHub →