Translate CPT titles in archives

[ad_1]

Hi,

I’m facing some trouble trying to translate the title of my CPT. I registered the CPT directly in the function file. The template is a custom one created from scratches. I’m using WordPress 6.0.2 and Polylang free version 3.2.7 with lingotek translation 1.5.9

I have activated in Polylang settings the translation of CPT and Taxonomy. Also configured in Lingotek Translation on automatic for my two CPT with all the objects checked.

I could translated all the pages created under these CPT to show it on the archives of both languages. But on the archive page of these CPT the title stay in the primary language.

The code of my CPT in the functions.php

function my_post_types() {
  register_post_type('realisations', [
      'label' => 'Réalisations',
      'lang' => 'fr',
      'public' => true,
      'menu_position' => 4,
      'menu_icon' => 'dashicons-portfolio',
      'supports' => ['title', 'editor', 'thumbnail'],
      'show_in_nav_menus' => true,
      'show_in_rest' => true,
      'has_archive' => true,
  ]);
  register_post_type('projets', [
    'label' => 'Projets',
    'lang' => 'fr',
    'public' => true,
    'menu_position' => 4,
    'menu_icon' => 'dashicons-portfolio',
    'supports' => ['title', 'editor', 'thumbnail'],
    'show_in_nav_menus' => true,
    'show_in_rest' => true,
    'has_archive' => true,
]);
}

This is the code of the archive page :

<?php get_header('alt'); ?>

<main>

<h1 id="h1"><?php _e(post_type_archive_title(), 'default'); ?></h1>

	<div id="container-projects">

	<?php if( have_posts() ) : while( have_posts() ) : the_post(); ?>
  
	<a href="<?php the_permalink(); ?>" class="post__link"><article class="post">

        	<?php the_post_thumbnail(); ?>

			<h3 class="h3"><?php the_title(); ?></h3>
                          
	</article></a>

	<?php endwhile; endif; ?>

	</div>
</main>
<?php get_footer('alt'); ?>

I’ve found several possibilities on internet and polylang website with _() or _e() functions but couldn’t figure out to make it works. They also don’t show in string translations pages.

Thanks if anyone can help me on this.

  • This topic was modified 1 hour, 3 minutes ago by emmanuelugo.
  • This topic was modified 1 hour, 3 minutes ago by emmanuelugo.

The page I need help with: [log in to see the link]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer