Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 9:00 – 18:00 - -
- - - - - - -

Supporter timezone: Africa/Cairo (GMT+02:00)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by Osama Mersal 6 months, 2 weeks ago.

Assisted by: Osama Mersal.

Author Posts
July 22, 2024 at 1:40 pm #15987139

adrienR-5

Background of the issue:
I have a CPT 'Fiches pratiques' and I set it to be 'Translatable' inside WPML > Settings > Post Types Translation. I've also set a different slug for each language. My main language is 'FR'.

Symptoms:
When I view a post of this CPT, I can see the custom slug for each language. But when I go to the archive page with SEOPress Breadcrumb, I can see that the custom archive slug is not translated. It's still /en/fiches-pratiques/, /it/fiches-pratiques/.

Questions:
Where can I translate the custom archive slug for a CPT?

July 22, 2024 at 1:49 pm #15987235

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi again, 🙂

Thanks for contacting WPML forums support. I'll be glad to help you today.

1) Please search for the "fiches-pratiques" string in String Translation.

If that didn't help, please replicate the issue on the hidden link">sandbox site and let me know to check it.

2) Could you please share your Debug information with me?
You can read a detailed explanation about it here. (http://wpml.org/faq/provide-debug-information-faster-support)
The debug info will give me much information about how your site is configured.

Best regards,
Osama

July 22, 2024 at 2:21 pm #15987356

adrienR-5

Hi again Osama 🙂

So when I don't set a custom archive slug inside my Post Types with MB AIO, the archive slug is translated thanks to WPML > Settings > Post Types Translation (and here we set a different translation for every slugs), but I want a plural name inside my archive page, that's why I used a custom rewrite slug in the first place,

So my slug for entry is /fiche-pratique/NAME_OF_FICHE_PRATIQUE/ and my archive post type is /fiches-pratiques/ (plural).

When I search for "fiches-pratiques" inside WPML > String Translation, I have nothing related to my custom archive slug, see screenshot

I shared my debug information of my staging website.

I created the CPT on your sandbox website.
As you can see, here is the custom archive slug for the main language (EN in your sandbox) : hidden link

And here the archive page with the 2 others languages: hidden link & hidden link

Let me know how I can have a custom archive slug which can be translated please.
For now the default slug for posts entries is working fine.

Example : hidden link, hidden link & hidden link

Thanks!

markuphero-f4fH2MUmpkR4SdWT3k7k.png
July 22, 2024 at 2:50 pm #15987568

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

Thanks for replicating the issue. I checked the re-write rule issue, and the workaround is to add a custom function to change the slug per language.

Alternatively, you can use the post's slug, which is translated via the settings page.

Best regards,
Osama

July 22, 2024 at 2:53 pm #15987579

adrienR-5

Hi Osama,

Yeah, like I told you I need to have a custom archive slug so it's in plural, so I cannot do with the post regular slug since it's not what I want.

The custom function to change the slug per language is what I would need I think, can you let me know how can I do that please?

July 22, 2024 at 4:17 pm #15987943

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

I'm afraid custom coding is outside our support scope. Please check this post or similar ones to see the function.

Best regards,
Osama

July 23, 2024 at 1:33 pm #15992576

adrienR-5

Hi,

Is this something that WPML are aware of and are working on it?

The solution provided didn't worked.

Thanks

July 23, 2024 at 1:44 pm #15992592

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

If the post type is created using PHP code, you can translate the slugs using String Translation because you would be able to wrap it with the GetText function.

I'll consult our compatibility team regarding this issue to check if we can find another workaround for it.

Best regards,
Osama

July 24, 2024 at 9:05 am #15997078

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

The Pro version of MetaBox is not fully compatible with WPML, so some features might not be working with WPML.

Could you please consult the MetaBox support team regarding this issue and let us know their findings?

Best regards,
Osama

July 24, 2024 at 4:53 pm #15999695

adrienR-5

Hi Osama,

That's not what the page you linked is saying: "Meta Box is fully compatible with WPML."

Anyway, I contacted Meta Box team and they told me:

"If you use the builder (UI) to create the CPT, there isn't a way to translate the custom archive slug. You can create the CPT with code and translate it with WPML.

Please follow the documentation
hidden link
https://developer.wordpress.org/reference/functions/register_post_type/"

Do you have any idea how I can translate the custom archive slug while registering the CPT with PHP code?

Thanks!

markuphero-8aLmFGzV2M9gSm6Tc55P.png
July 25, 2024 at 12:19 pm #16003447

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

1) Thanks for your reply. Please check the attached screenshot.

2) You need to register the slug for translation in order to be able to translate it using String Translation. Kindly check the following example.

Step 1: Register the slug for translation:

// Register the custom post type slug for translation
add_action('init', 'register_custom_post_type_slug_for_translation');

function register_custom_post_type_slug_for_translation() {
    if (function_exists('icl_register_string')) {
        icl_register_string('Custom Post Type', 'Book Slug', 'book');
    }
}

Step 2: Retrieve the Translated Slug

function my_custom_post_type() {
    // Retrieve the translated slug
    $translated_slug = 'book';
    if (function_exists('icl_t')) {
        $translated_slug = icl_t('Custom Post Type', 'Book Slug', 'book');
    }

    $args = array(
        'label'               => __( 'Books', 'text_domain' ),
        'description'         => __( 'Book Description', 'text_domain' ),
        'labels'              => array(
            'name'                => _x( 'Books', 'Post Type General Name', 'text_domain' ),
            'singular_name'       => _x( 'Book', 'Post Type Singular Name', 'text_domain' ),
            'menu_name'           => __( 'Books', 'text_domain' ),
            'name_admin_bar'      => __( 'Book', 'text_domain' ),
            'archives'            => __( 'Item Archives', 'text_domain' ),
        'rewrite'             => array( 'slug' => $translated_slug ),
    );

    register_post_type( 'book', $args );
}

add_action( 'init', 'my_custom_post_type', 0 );

Best regards,
Osama

July 27, 2024 at 4:29 pm #16010973

adrienR-5

Hi Osama,

Thanks for the reply but there is no screenshot attached to your last post, is this normal?

July 28, 2024 at 10:05 am #16011871

Osama Mersal
Supporter

Languages: English (English ) Arabic (العربية )

Timezone: Africa/Cairo (GMT+02:00)

Hi,

I added the screenshot.

Best regards,
Osama

2024-07-25_15-11-10.jpg

The topic ‘[Closed] MB AIO + Bricks + WPML – How to translate the custom archive slug for a CPT’ is closed to new replies.