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.

This topic contains 10 replies, has 2 voices.

Last updated by Mihai Apetrei 6 months ago.

Assigned support staff: Mihai Apetrei.

Author Posts
April 16, 2019 at 8:02 am

marcB-30

I am trying to: Translate custom post type slug

Link to a page where the issue can be seen: hidden link

I expected to see: Link von ersten bild: hidden link

Instead, I got: Link von ersten bild: hidden link

April 16, 2019 at 12:24 pm #3621929

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi and thank you for contacting WPML Support!

I will be happy to help you with this.

From what I can see, "wandern" is set as the original slug for the German language.

I will also attach 2 screenshots from the WPML > Settings > Custom Post Type translation section and from WPML > String Translation.

I don't know how this custom post type is registered or where (it can be done by using a plugin, it can come with the theme that you are using or it can be custom coded) but if you don't have this information, you should be able to just go to WPML > String Translation > search for "wandern" > check the box on the left for that field and then scroll and go with the "Change the language of the selected strings" button.

If it was registered with a plugin or with a theme, you should be able to change the default slug from the plugin/theme settings, or if it custom coded, you could change it inside the code.

Please let me know if you found this information helpful and if it solved your issue.

If you have more information about how the CPT is registered, that would help, too as WPML is used to translate existing strings/slugs into other languages so the original/default language slug should be changed from the place where it was created initially, not with the help of WPML.

I will be waiting for your response.

Kind regards,
Mihai Apetrei

April 17, 2019 at 5:04 am #3627163

marcB-30

Hi and thank you for your answer!

We initiate custom post type direct in functions.php, I am sending the specific code:

add_action( 'init', 'create_post_type_wandern' );
	function create_post_type_wandern() {
	  register_post_type( 'wandern',
	    array(
	      'labels' => array(
	        'name' => __( 'Wanderprogramm' ),
	        'singular_name' => __( 'Wanderprogramm' )
	        ),
	      'public' => true,
	      'has_archive' => 'wandern-archive',
	      'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes', 'taxonomy'),
	      'hierarchical' => true
	      )
	    );
	}

I hope it can help!

Best regards

April 17, 2019 at 12:01 pm #3630405

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi.

Thank you for the information.

I think the slug is taken automatically from this line [php]register_post_type( 'wandern',[php].

I think you could use the " 'slug' => string Customize the permalink structure slug " array functionality that you can find here: https://codex.wordpress.org/Function_Reference/register_post_type

I am also attaching 2 screenshots from that page so that I can show you what I mean.

Using that, you should be able to set a custom specific slug for the default custom post type you created. This way, you could change the slug for the default language of the site.

Please let me know if that worked out fine for you.

Kind regards,
Mihai

April 17, 2019 at 12:35 pm #3630787

marcB-30

Hi, thank you for your answer!

I have changed the code, the way you suggesting:

add_action( 'init', 'create_post_type_wandern' );
	function create_post_type_wandern() {
	  register_post_type( 'wandern',
	    array(
	      'labels' => array(
	        'name' => __( 'Wanderprogramm' ),
	        'singular_name' => __( 'Wanderprogramm' )
	        ),
	      'public' => true,	      
	      'has_archive' => 'wandern-archive',
	      'supports' => array( 'title', 'editor', 'thumbnail', 'page-attributes', 'taxonomy'),
	      'hierarchical' => true,
	      'rewrite' => array( 'slug' => 'wandern' ), //changed
	      )
	    );
	}

But unfortunately it did not help.

Best regards
David

April 17, 2019 at 1:38 pm #3631387

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi.

From my understanding, you wanted to have the "randonnees" slug for the German language (exactly as you set it for French already) instead of "wandern" so in order to accomplish that, you would need to change that line into this:

'rewrite' => array( 'slug' => 'randonnees' ),

Please let me know if that helps or, if you think that I understood things wrong and you actually want to accomplish something totally different, can you please explain a bit more so that I can better understand what you are looking for?

I will be waiting for your response.

Kind regards,
Mihai

April 17, 2019 at 1:52 pm #3631463

marcB-30

Hi!

for german, I need "Wandern", for french "randonnees". I need to translate custom post type slug to different languages, I follow this tutorial: https://wpml.org/documentation/getting-started-guide/translating-page-slugs/#enabling-custom-post-type-name-localization-in-wpml

Thank you!

Best regards
David

April 17, 2019 at 2:34 pm #3631955

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi.

Thank you for the explanation - then you do not need to use that extra code in the custom post type creation.

From what I can see, French is already translated and it works.

Here is the test I've made:

DE: hidden link
FR: hidden link

Please let me know if that is what you mean.

Kind regards,
Mihai

April 17, 2019 at 2:40 pm #3631965

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

I also went into WPML > Languages and enabled the footer language switcher for testing purposes.

It seems that there is something wrong with the language switcher you implemented at the top on the left side as it seems that it is not the one generated straight by WPML - it is somehow implemented differently and that one is not working correctly.

I can see even from the source code that the generated code in the footer follows the source code that WPML outputs while the language switcher at the top doesn't.

So the footer language switcher that is generated directly by WPML works perfectly, the issue is with the one on the top-left.

I hope that this information helps you to understand what might cause the issue.

Kind regards,
Mihai

April 18, 2019 at 6:45 am #3636363

marcB-30

Hi Mihai,

thank you for your answer! But there is still something wrong. Next week, I will search for it and write you back. Leave this question still open, please.

Best regards
David

April 18, 2019 at 3:38 pm #3640451

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+03:00)

Hi David.

Sure, I will leave the ticket open for the moment and I will assign it to you.

It is obviously something wrong with the language switcher from the top as the one WPML is generating by default works.

From my tests, you get a 404 error only when you try to switch the language of the page from the top-left language switcher - from the footer language switcher, it changes the language with no errors.

Kind regards,
Mihai

The topic ‘[Closed] Custom post type are not translated’ is closed to new replies.