I’m developing a website using the WPML plugin. And I would like to know which is the better option, or even the correct way to change classes or IDs between the languages.
Sample code:
<ul id="<?php _e('menu-topo'); ?>">
<ul id="<?php if ($lang = 'en') { echo "menu-topo-en"; } else { echo "menu-topo"; } ?>
I’m not sure that the _e
function is supposed to be used this way so if someone could clarify this for me it would help me a lot, thanks.
_e() will translate the text passed as a argument to the language your site is currently set up to use (if the translation exists).
Anyway, don’t do that. Use it for text visible on the website, not for IDs/classes etc. To create context based css rules, simply add the WPML language ID as a body class:
then style the elements you need to using something like:
It’s faster, and you keep your code easy to maintain.