Saltar navegación

Este es el foro de soporte técnico de WPML, el plugin multilingüe de WordPress.

Todas las personas pueden leerlo pero solo los clientes de WPML pueden ingresar comentarios. El equipo de WPML responde en los foros 6 días a la semana, 22 horas por día.

Este tema contiene 3 respuestas, tiene 1 voz.

Última actualización por davidC-152 hace 1 año, 11 meses.

Autor Entradas
junio 27, 2023 en 9:55 am #13901075

davidC-152

Hi,

I don't know if you provide support in spanish, so I'll write in english. If you provide support in spanis, just let me know and I'll write in spanish.

I've a problem with the website enlace oculto. The problem is the language swticher provided by WPML is not working properly with a custom post type. The website is running with the last versions of WordPress and WPML.

The site is configured with 2 languages: spanish and galician. The main language is spanish.

This custom post type is configured in WPML to be translatable. If I create a post of this type in spanish and translate it to galician when I visit the spanish post and click in the language switcher I get a 404 not found error. The problem is the language switcher is not adding the language preffix in the URL and that is the reason because it fails.

For example: I have the spanish URL: enlace oculto

This post is translated to galician. The translated post has the URL: enlace oculto

(the url is very similar because many words in spanish don't neet to be translated to galician, so the only difference is between the word "aguas" and its translation "augas")

When I visit the spanish URL, if I hover the language switcher, this is the URL I see: enlace oculto

As you can see this URL lacks the gl language preffix and that is what is causing the 404 error.

Please, how can I solve this issue?

In case you need access to the site, just let me know.

junio 27, 2023 en 10:46 am #13901629

davidC-152

I've found the problem. It is this custom code used to add a preffix to the URL of the posts of this type:

function add_rewrite_rules( $wp_rewrite )
{
    $new_rules = array(
        'noticias/(.+?)/?$' => 'index.php?post_type=post&name='. $wp_rewrite->preg_index(1),
    );

    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_action('generate_rewrite_rules', 'add_rewrite_rules'); 

function change_blog_links($post_link, $id=0){

    $post = get_post($id);

    if( is_object($post) && $post->post_type == 'post'){
      return home_url('/noticias/'. $post->post_name.'/');
    }

    return $post_link;
}
add_filter('post_link', 'change_blog_links', 1, 3);

If I remove this custom code then it works, but I want to preserve the "noticias" preffix in the URLs of the posts of this type. So, how could I modifiy the URL in the language switcher to fix it preserving this preffix?

junio 27, 2023 en 10:57 am #13901677

davidC-152

I've just solved it adding the preffix "noticias" in the permalink configuration and removing the custom code.