Home›Support›English Support›[Resolved] How to translate archive page of custom CPT? And remove translations?
[Resolved] How to translate archive page of custom CPT? And remove translations?
This thread is resolved. Here is a description of the problem and solution.
Problem: The client needed to translate archive pages for custom post types (CPTs) and deactivate/delete unwanted indexed translated archive pages. Solution: We recommended manually registering the CPTs to avoid issues with translations and indexing. Additionally, the client provided a custom code snippet to disable the archive slug for some CPTs in all languages other than the default. Here is the code snippet:
will fetch posts only in the specific language by bypassing WPML filters.
If this solution does not apply to your case, or if it seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket.
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.
Background of the issue:
We have some links that are indexed of some archive page and while we don't know how to translate those archive pages in the first place, we would like to know how we can deactivate/delete those indexable URLs which aren't wanted.
Symptoms:
We don't know how to translate archive pages of custom CPT and want to remove unwanted indexed translated archive pages.
Questions:
How to translate archive pages of custom CPT?
How to deactivate/delete unwanted indexed translated archive pages?
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+01:00)
To troubleshoot this problem, I'll install the Duplicator plugin and generate packages for further debugging purposes. I'll ensure to exclude all media files to maintain a minimal package size. You can find more information about the process here: [link](https://wpml.org/faq/provide-supporters-copy-site/). Please confirm if this approach is acceptable to you.
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+01:00)
I did not change anything, in fact I don't even have access to your site as logins don't seem to work no longer. I send the package to our 2nd tier only.
According to them though, this is replicable with ACF or CPT UI if the post type is set to "Not translatable". Setting the post type to "Translatable - only show translated content" solves this issue - as long there are not any translated posts.
So doing this make my archive page not offering other translations in the dropdown.
But those links are still accessible and set to "index", example here: hidden link
How can I prevent them to be generated and accessible?
Also how do I translate those archive page for the languages I need to translate?
Hey Bruno, I'm wondering if this is a real question, if I disable Metabox AIO all my CPTs are gone so obviously everything related to CPTs will be error 404, I don't know how it can help us
Languages: English (English )German (Deutsch )French (Français )
Timezone: Europe/Zagreb (GMT+01:00)
Can you please try the following:
1. Add the custom code provided to your theme's `functions.php` file. This code prevents the registration of the Custom Post Type (CPT) on non-default languages by removing the `mb_cpt_load` action before it is triggered.
2. Verify that the Custom Post Type (CPT) does not register in non-default languages by visiting your site in different language settings. If the CPT appears only in the default language, the issue should be resolved.
Your code snippet was a bit too hard, since it disable all CPTs for the others languages, which I don't want.
I created this code snippet, which just disable the archive slug for some CPTs in all other languages than the default, that's exactly what I wanted, to avoid unwanted archive slug for other languages.
```
function sws_remove_cpt_archive_for_other_languages() {
// Get the current and default language
$current_language = apply_filters( 'wpml_current_language', null );
$default_language = apply_filters( 'wpml_default_language', null );
// Check if the current language is not the default language
if ( $current_language !== $default_language ) {
// Remove the archive page for specified CPTs
add_action('template_redirect', 'sws_disable_cpt_archive');
}
}
function sws_disable_cpt_archive() {
// Array of CPTs for which to disable the archive page
$cpts_to_disable = array(
'cpt1',
'cpt2',
'cpt3',
); // Examples, replace by yours
// Check if the current request is for any of the specified CPTs' archive page
foreach ($cpts_to_disable as $cpt) {
if (is_post_type_archive($cpt)) {
// Redirect to the homepage of the current language
wp_redirect(apply_filters('wpml_home_url', home_url()));
exit();
}
}
}