Sauter la navigation

Ce sujet est résolu. Voici une description du problème et de la solution.

Problem:
The client is experiencing issues with hard-coded links in their PHP WordPress files, resulting in incorrect URLs with a double-slash in the English version of their site.
The code uses looks like this:

<?php echo home_url();?>/page-slug/">

Solution:
home_url() will return the home url without a trailing slash.
Here we can offer different solutions:
1. Use home_url( '/' ) to force the inclusion of a trailing slash, and then remove the initial slash from all links.
Example:

<?php echo home_url( '/' );?>page-slug/">

For reference, see the WordPress home_url function documentation.

2. Utilize the

wpml_home_url

hook
For more information, check out the wpml_home_url hook documentation.

3. Replace the hard-coded links with a WordPress menu that can be translated and synchronized using WPML.
You can find guidance on this process in the Translating Menus documentation.

If this solution does not seem relevant to your situation, please do not hesitate to open a new support ticket with us for further assistance. You can do so by visiting the WPML support forum.

Il s'agit du forum d'assistance technique de WPML, le plug-in multilingue pour WordPress.

Il est accessible à tous, toutefois seuls les clients de WPML peuvent y publier leurs messages. L'équipe du WPML répond sur le forum 6 jours par semaine, 22 heures par jour.

Marqué : 

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Nicolas V. Il y a 1 année et 4 mois.

Assisté par: Nicolas V..

Auteur Articles
janvier 15, 2024 à 3:43 pm #15186077

marcJ-14

Hello,

My plugin is set up so that the main version is FR, url = lien caché and I have a second version in EN where the URL is lien caché.
OK, the problem is with my URLs between FR and EN when the links are hard-coded in the code. If you have a look at the footer for example: the links are written in my php wordpress files (see screenshot in attachment). And it's generating a problem on the English URLs : lien caché. There is a double-slash !

So I'd like to correct these URLs so that there's only one slash, or even better, so that the link displayed is the real EN link! Currently, the urls automatically redirect to the real urls. Example: lien caché redirects to lien caché

Can you help me?

Thanks in advance,
Marion

exemple-defontaine.jpg
janvier 15, 2024 à 4:47 pm #15186262

Nicolas V.
Supporter

Les langues: Anglais (English ) Français (Français )

Fuseau horaire: America/Lima (GMT-05:00)

Bonjour,

Je pense que le problème est l'utilisation de home_url qui ne donne pas le slash sur la langue principale.

Je vois plusieurs solutions:
1. home_url( '/' )
Cela devrait forcer l'utilisation du slash et vous devrez retirer le premier slash de tous vos liens.
Ref: https://developer.wordpress.org/reference/functions/home_url/

2. wpml_home_url
Vous pouvez utiliser notre propre hook.
Ref: https://wpml.org/wpml-hook/wpml_home_url/

3. Vous pouvez remplacer ces liens "hardcodés" par un menu WordPress que vous pourrez traduire et synchroniser.
Ref: https://wpml.org/documentation/getting-started-guide/translating-menus/

janvier 16, 2024 à 12:48 pm #15189765

marcJ-14

Merci beaucoup Nicolas ! J'ai utilisé la 1ère méthode et cela a bien fonctionné.