[Resolved] Running custom php depending on the language selected
This thread is resolved. Here is a description of the problem and solution.
Problem:
How to code PHP as per current language?
Solution:
You have to use "ICL_LANGUAGE_CODE" to get your current language.
Here is the sample code/structure
function my_custom_function() {
if(ICL_LANGUAGE_CODE=='en'){
<!--- your code to english--->
} elseif(ICL_LANGUAGE_CODE=='de'){
<!---your code to german--->
} elseif(ICL_LANGUAGE_CODE=='fr'){
<!---your code to french---
Global site tag (gtag.js) - Google Analytics -->
} elseif(ICL_LANGUAGE_CODE=='es'){
<!---your code to spanish--->
}
}
Modify your code according to this and you will get what you want.
67% of people find this useful.
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.
I am customizing the "my account" page in Woocommerce
I use my own php code to add bookmarks to the "my account" menu. The content of the added bookmarks is displayed using shortcode to custom html blocks.
Wmpl doesn't explain these bookmarks and some content from custom html blocks to me. I tried various settings including scanning while rendering pages.
I thought that I could make custom php separate for each language, thus creating dedicated content for individual languages, and that's why I need help.
How to modify php code to make it active only for a given language?
You have to use "ICL_LANGUAGE_CODE" to get your current language.
Here is the sample code/structure
function my_custom_function() {
if(ICL_LANGUAGE_CODE=='en'){
<!--- your code to english--->
} elseif(ICL_LANGUAGE_CODE=='de'){
<!---your code to german--->
} elseif(ICL_LANGUAGE_CODE=='fr'){
<!---your code to french---
Global site tag (gtag.js) - Google Analytics -->
} elseif(ICL_LANGUAGE_CODE=='es'){
<!---your code to spanish--->
}
}
Modify your code according to this and you will get what you want.
Thank you very much,
I have modified my php and it works. thank you again.
Manage Cookie Consent
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.