I would like to add a piece of javascript, but ONLY to our english pages. We elected to not have the english pages be /en, they are just the root domain. But, we do NOT want this javascript to display on any translated pages (/fr, /es, etc). Is there a way to do this?
In the future, we would also add Javascript only to specific language databases (/fe, /es, etc). So we would need to understand how to do both.
Welcome to the WPML support forum.
You can use our hook 'wpml_current_language' to get the current language and then use an IF statement to add your JS only if the language is EN.
1. If I wanted to add my javascript into that "quick example" where would I put it? The script is from a source URL like this: <script src="fake-url"></script>
2. How would this script change for other languages? Do I just change out the "my_current_lang" section?
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.