KLicheR / wp-polylang-translate-rewrite-slugs

Wordpress plugin to help translate post types rewrite slugs with the Polylang plugin.
110 stars 45 forks source link

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:

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;
});
?>