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.
Tagged: Custom Work
This topic contains 5 replies, has 2 voices.
Last updated by barjD 1 year, 7 months ago.
Assisted by: Christopher Amirian.
Author | Posts |
---|---|
August 25, 2023 at 10:46 pm #14293947 | |
barjD |
Tell us what you are trying to do? I am trying to deactivate all plugins on my site to troubleshoot something. Every time I do so, I get a "Critical error" message on my site and nothing works: Fatal error: Uncaught Error: Undefined constant "ICL_LANGUAGE_CODE" in /nas/content/live/dhahanstage/wp-content/themes/infinity-pro/functions.php:66 Stack trace: #0 /nas/content/live/dhahanstage/wp-includes/class-wp-hook.php(312): wpml_lang_body_class(Array) #1 /nas/content/live/dhahanstage/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #2 /nas/content/live/dhahanstage/wp-includes/post-template.php(862): apply_filters('body_class', Array, Array) #3 /nas/content/live/dhahanstage/wp-content/themes/genesis/lib/functions/markup.php(319): get_body_class() #4 /nas/content/live/dhahanstage/wp-includes/class-wp-hook.php(312): genesis_attributes_body(Array) #5 /nas/content/live/dhahanstage/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array) #6 /nas/content/live/dhahanstage/wp-content/themes/genesis/lib/functions/markup.php(214): apply_filters('genesis_attr_bo...', Array, 'body', Array) #7 /nas/content/live/dhahanstage/wp-content/themes/genesis/lib/functions/markup.php(232): genesis_parse_attr('body', Array, Array) #8 /nas/content/live/dhahanstage/wp-content/themes/genesis/lib/functions/markup.php(108): genesis_attr('body', Array, Array) #9 /nas/content/live/dhahanstage/wp-content/themes/genesis/header.php(41): genesis_markup(Array) #10 /nas/content/live/dhahanstage/wp-includes/template.php(785): require_once('/nas/content/li...') #11 /nas/content/live/dhahanstage/wp-includes/template.php(720): load_template('/nas/content/li...', true, Array) #12 /nas/content/live/dhahanstage/wp-includes/general-template.php(48): locate_template(Array, true, true, Array) #13 /nas/content/live/dhahanstage/wp-content/themes/genesis/lib/framework.php(24): get_header() #14 /nas/content/live/dhahanstage/wp-content/themes/genesis/single.php(15): genesis() #15 /nas/content/live/dhahanstage/wp-includes/template-loader.php(106): include('/nas/content/li...') #16 /nas/content/live/dhahanstage/wp-blog-header.php(19): require_once('/nas/content/li...') #17 /nas/content/live/dhahanstage/index.php(17): require('/nas/content/li...') #18 {main} thrown in /nas/content/live/dhahanstage/wp-content/themes/infinity-pro/functions.php on line 66 There has been a critical error on this website. Is there any documentation that you are following? Please see here: https://wpml.org/forums/topic/rtl-blank-space-when-screen-size-changes-or-using-inspect-element-in-chrome/ Is there a similar example that we can see? You can input // add lang code in body class return $classes; Into a child theme's functions.php file and then deactivate all plugins What is the link to your site? hidden link I am wondering if someone can help with a corrected solution to include language codes as body classes while not having the whole site go down if plugins are disabled? Thank you |
August 27, 2023 at 1:22 pm #14296399 | |
Christopher Amirian WPML Supporter since 07/2020
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, The "ICL_LANGUAGE_CODE" is deprecated and it is better to use the method below: https://wpml.org/faq/how-to-get-current-language-with-wpml/ Just so you know, WPML adds language code by default to the HTML tag's lang attribute. So if for example, you want to select a page in Panjabi to use in CSS or Javascript you can add: html[lang="pa"] Then the rest of selectors. For example a class called container only in Panjabi will be selected this wayL html[lang="pa"] .container { Thanks. |
August 28, 2023 at 7:38 pm #14303129 | |
barjD |
Hello, thank you. Can you please clarify, because if I take out: // add lang code in body class return $classes; Then the css classes I have defined for .pa and .pa_sh don't work. Your solution also didn't work for me 🙁 As an example of how I was using the CSS, when I take that code out of functions.php, and I use in style.css: html[lang="pa"] .site-title a { It also doesn't work (I cleared website cache and checked incognito window). Do you have an example of it working in this type of context? However, can you explain more about modifying or replacing the ICL_LANGUAGE_CODE which is now depreciated? Would I change the code above to: // add lang code in body class return $classes; the code above gives me an error... but to be honest I'm confused how to use the solution on the page you gave me. I am open to the best way to do this, but I am not sure how to solve this, since the html[lang="pa"] solution is not working... 🙁 Thank you for your help |
August 29, 2023 at 12:21 am #14303441 | |
barjD |
I figured out the language code is supposed to be pa-in for Punjabi in Gurmukhi, not just pa. If you can still help with that it would be very appreciated. Thank you |
August 30, 2023 at 11:37 am #14312915 | |
Christopher Amirian WPML Supporter since 07/2020
Languages: English (English ) Timezone: Asia/Yerevan (GMT+04:00) |
Hi there, You can use the hook mentioned here: https://wpml.org/wpml-hook/wpml_current_language/ A sample code that you can work your ways around can be this: function my_custom_body_class($classes) { $lang = apply_filters('wpml_current_language', NULL); if ($lang) { $classes[] = 'lang-' . $lang; // This will add a class like "lang-en" for English, "lang-fr" for French, etc. } return $classes; } add_filter('body_class', 'my_custom_body_class'); Please consider that we are not able to give customization code as it is outside of our support scope. If you need additional help with the code you can ask for help from a developer: Thanks. |
September 3, 2023 at 11:44 pm #14333027 | |
barjD |
Thank you very much |
September 3, 2023 at 11:45 pm #14333033 | |
barjD |
Thank you for your helpfulness |