microb14
microb14

Reputation: 483

Translate custom post type slug

I'm using Wordpress 5 et WPML. I have a lot of custom type. Each custom type has his slug.

My website is in english and french

Exemple :

I need to translate city and country in french :

How can i translate the slug ?

Example of cuctom type :

$rewrite = array(
        'slug'                  => 'city',
        'with_front'            => true,
        'pages'                 => true,
        'feeds'                 => true,
    );
    $args = array(
        'label'                 => __( 'Les villes', 'test' ),
        'description'           => __( 'Les villes', 'test' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'thumbnail' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-admin-home',
        'show_in_admin_bar'     => false,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'rewrite'               => $rewrite,
        'capability_type'       => 'page',
        'show_in_rest'          => true,
    );

    register_post_type( 'villes', $args );
}
add_action( 'init', 'villes_post_type', 0 );

Upvotes: 0

Views: 2015

Answers (1)

Puya Fazlali
Puya Fazlali

Reputation: 536

Since you are using WPML, you can achieve this with an addon for WPML.

  1. Install and activate the "WPML String Translation" addon.
  2. Go to WPML -> Settings
  3. Under the "Slug translations" section, check "Translate custom post and taxonomy base slugs (via WPML String Translation)". WPML Slug translations section
  4. On the same page, scroll down, under "Post Types Translation", find the name of your custom post type.
  5. Check "Set different slugs in different languages for [post type name]" different slug for different language with WPML
  6. Enter the translated post type slug for each language.
  7. Click the "Save" button.

Upvotes: 2

Related Questions