Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
I am trying to: Translate SEO title and meta description for custom post types for each of my website's languages. I can see the string in the "translation strings" screen (and I add the translation here), but in the frontend site, the custom post type archive page only shows meta title and description in the default language.

Solution:
Version 14.0 of the Yoast SEO plugin came out with some major changes. Some changes affected the compatibility with WPML. However, everything's gonna be fixed in Yoast SEO Multilingual 1.2.0. Until then you can use the fix presented in the errata below.

Relevant Documentation:
https://wpml.org/errata/search-page-title-in-wordpress-yoast-seo-is-not-translating/

100% of people find this useful.

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 12 replies, has 2 voices.

Last updated by juanA-23 4 years, 5 months ago.

Assisted by: Radu.

Author Posts
May 12, 2020 at 8:20 pm #6116677

juanA-23

I am trying to: Translate SEO title and meta description for custom post types for each of my website's languages. I can see the string in "translation strings" screen (and I add the translation here), but in the frontend site, the custom post type archive page only shows meta title and description in default language.

Link to a page where the issue can be seen: hidden link user: Pino / password: @Cocinas2019

I expected to see: The title and meta description in the custom post type archive page translated in english and français

I have tried to deactivate all plugins, and I have WPML and the other related plugins updated to the last version. I have uploaded some images, so you can see that the strings appears, but not in the frontend site.

frontend.png
string translation screen.png
cocinas custom post type in default language spanish.png
May 14, 2020 at 12:00 pm #6131855

Radu

Hey Juan,

Thank you for reaching out to the WPML support!

I tried to use the credentials that you attached for the authorization, but they didn't work. Can you send them again, please?

Also, it would be great if you could give me access to the dashboard area too. This way I'll be able to have a closer look at the settings and see what might be causing this issue. Also, I'll be able to copy the same settings on my website to see if I can replicate the issue.

The next reply is set to be private so you can safely send me the credentials.

Thanks,
Radu

May 24, 2020 at 8:31 pm #6205695

Radu

Hey Juan,

Can you tell me if you're making any change to this element, please?
Also, as I can see, you're using a custom theme. Can you install a default theme (like Twenty Twenty), and tell me if you still have this issue, please? I just want to make sure that that this is not an issue caused by the code you are using on the current theme.

Thanks,
Radu

May 29, 2020 at 5:09 pm #6251623

juanA-23

Hi! Same problem changing to Twenty Twenty theme

Captura de pantalla 2020-05-29 a las 19.05.13.png
May 31, 2020 at 1:02 pm #6260071

Radu

Hey Juan,

Can you go back here:
hidden link

make sure that the language selected on the top admin bar is English and change the title and description, please?

I added EN just as a test to the end of the title and it appears fine in English:
hidden link

while staying untouched in Spanish:
hidden link

Thanks,
Radu

June 1, 2020 at 9:32 am #6264375

juanA-23

Hi Radu! Thanks for your response.

You have posted the wrong url for the spanish content.
This is english content: hidden link
And this is spanish content: hidden link

As you can see, the title is common for both languages.

As I understood, the translation management for titles and meta tags has to be set at the string translation configuration of wpml, not in the Search Appearance section.

Thanks!

June 2, 2020 at 1:17 pm #6274501

Radu

Hey Juan,

I looked at the way that the Yoast plugin is saving the title and description for the Cocinas post type archive. It seems that this is saved in wpseo_titles → title-ptarchive-cocinas and metadesc-ptarchive-cocinas, which are available for translation here:
hidden link

In this case, is there any chance that you could tell me how did you create this custom post type (maybe share the code you used) so I can use it on my testing website and try to translate the title and description too.

Thanks,
Radu

June 3, 2020 at 8:33 am #6280809

juanA-23

Hi Radu, here you have the code i used in the functions.php file of my theme:

function codex_custom_init() {



		$labels = array(
		'name'               => _x( 'Contenido de cocinas', 'post type general name', 'your-plugin-textdomain' ),
		'singular_name'      => _x( 'Contenido de cocinas', 'post type singular name', 'your-plugin-textdomain' ),
		'menu_name'          => _x( 'Cocinas', 'admin menu', 'your-plugin-textdomain' ),
		'name_admin_bar'     => _x( 'Cocinas', 'add new on admin bar', 'your-plugin-textdomain' ),
		'add_new'            => _x( 'Añadir nuevo', 'book', 'your-plugin-textdomain' ),
		'add_new_item'       => __( 'Añadir nuevo contenido de cocinas', 'your-plugin-textdomain' ),
		'new_item'           => __( 'Nuevo contenido de cocinas', 'your-plugin-textdomain' ),
		'edit_item'          => __( 'Editar contenido de cocinas', 'your-plugin-textdomain' ),
		'view_item'          => __( 'Ver contenido de cocinas', 'your-plugin-textdomain' ),
		'all_items'          => __( 'Todos los contenidos de cocinas', 'your-plugin-textdomain' ),
		'search_items'       => __( 'Buscar en contenido de cocinas', 'your-plugin-textdomain' ),
		'parent_item_colon'  => __( 'Contenido de cocinas superior', 'your-plugin-textdomain' ),
		'not_found'          => __( 'Ningún contenido de cocinas encontrado', 'your-plugin-textdomain' ),
		'not_found_in_trash' => __( 'Ningún contenido de cocinas encontrado en la papelera.', 'your-plugin-textdomain' )
	);
	
	  $args = array(
	    'label' => 'Cocinas',
	    'public' => true,
	    'show_in_rest' => true,
	    'publicly_queryable' => true,
	    'show_ui' => true, 
	    'show_in_menu' => true, 
	    'query_var' => true,
	    'capability_type' => 'post',
	    'has_archive' => true, 
	    'hierarchical' => false,
	    'menu_position' => 4,
	    'labels' => $labels,
	    'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' )
	  ); 
	  register_post_type('cocinas', $args);


  
}
add_action( 'init', 'codex_custom_init' );
June 9, 2020 at 9:49 am #6329295

Radu

Hey Juan,

Thank you for sharing this code with me. It seems that you're not the only one having this issue. My colleagues are investigating this issue right now and looking for a fix.

I will keep you posted about the progress we're making on this one. I will also try to come back with an early fix too, if possible.

Thanks,
Radu

June 9, 2020 at 10:37 am #6329723

juanA-23

Thanks Radu, i'll be waiting for your reply! 🙂

June 10, 2020 at 12:46 pm #6342115

Radu

Hey Juan,

Can you try to add this code to your website:

add_filter( 'wpseo_title', 'wpml_wpseo_title', 10, 2 );
add_filter( 'wpseo_opengraph_title', 'wpml_wpseo_title', 10, 2 );
function wpml_wpseo_title( $title, $presentation ) {
	switch ( $presentation->model->object_type ) {
		case 'post-type-archive':
			$key = 'title-ptarchive-' . $presentation->model->object_sub_type;
			break;
		case 'system-page':
			$key = 'title-' . $presentation->model->object_sub_type . '-wpseo';
			break;
		default:
			$key = false;
	}

	if ( $key ) {
		$option = get_option( 'wpseo_titles' );
		if ( isset( $option[ $key ] ) ) {
			$title = wpseo_replace_vars( $option[ $key ], $presentation );
		}
	}

	return $title;
}

add_filter( 'wpseo_metadesc', 'wpml_wpseo_desc', 10, 2 );
add_filter( 'wpseo_opengraph_desc', 'wpml_wpseo_desc', 10, 2 );
function wpml_wpseo_desc( $title, $presentation ) {
	switch ( $presentation->model->object_type ) {
		case 'post-type-archive':
			$key = 'metadesc-ptarchive-' . $presentation->model->object_sub_type;
			break;
		case 'system-page':
			$key = 'metadesc-' . $presentation->model->object_sub_type . '-wpseo';
			break;
		default:
			$key = false;
	}

	if ( $key ) {
		$option = get_option( 'wpseo_titles' );
		if ( isset( $option[ $key ] ) ) {
			$title = wpseo_replace_vars( $option[ $key ], $presentation );
		}
	}

	return $title;
}

and check the title and description now, please? I tried it on my website and it works very well. This fix will also be added to the next update of the Yoast WPML glue plugin.

It seems that some major changes were made lately on the Yoast plugin and that's why this part was broken.

Thanks,
Radu

June 10, 2020 at 2:07 pm #6342681

juanA-23

Thank you so much Radu, the code works like a charm!

I have to delete the code when the next yoast wpml plugin will be available?

Thanks! 😀