WP Manifestindependent plugin directory
manifest / i18n / wp-polylang-translate-rewrite-slugs

Polylang - Translate URL Rewrite Slugs

Help translate post types rewrite slugs.

by KLicheR · github.com/frc/wp-polylang-translate-rewrite-slugs · website

3stars
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/frc/wp-polylang-translate-rewrite-slugs/archive/refs/heads/main.zip

Readme

Polylang - Translate URL Rewrite Slugs

WordPress plugin that add rewrite url slugs translation feature to Polylang.

Work in progress ;)

Upgrade notice < 0.3.0

If you used a version prior to 0.3.0, the plugin will probably crash as the structure of the param for the "pll_translated_post_type_rewrite_slugs" filter has changed.

Translate Post Type URLs

Translate rewrite slugs for post types by doing 5 things:

  • Remove original extra rewrite rules and permastruct for these post types;
  • Translate the extra rewrite rules and permastruct for these post types;
  • Stop Polylang from translating rewrite rules for these post types;
  • Fix "get_permalink" for these post types.
  • Fix "get_post_type_archive_link" for these post types.

To translate a post type rewrite slug, add the filter "pll_translated_post_type_rewrite_slugs" to your functions.php file or your plugin and add the "has_archive" and "rewrite" key has you normally do for the params of the "register_post_type" Wordpress function but add it for each post type and language you want.

Example

<?php
add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
    // Add translation for "product" post type.
    $post_type_translated_slugs = array(
        'product' => array(
            'fr' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'produit',
                ),
            ),
            'en' => array(
                'has_archive' => true,
                'rewrite' => array(
                    'slug' => 'product',
                ),
            ),
        ),
    );
    return $post_type_translated_slugs;
});
?>

Read the full README on GitHub →

Releases

TagPublished
0.3.7.6 Sep 16, 2021

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.