Translate CPT titles in archives
-
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.
The page I need help with: [log in to see the link]
- The topic ‘Translate CPT titles in archives’ is closed to new replies.