SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
Hi, I need to change the HTML lang="" attribute for just a couple of pages on a Gantry 5 site (Helium theme).
I've tried to do this via the locale() and language_attributes() Wordpress filters in the functions.php file, but that isn't changing the HTML lang attribute.
I see that the nucleus template file page.html.twig outputs the "gantry.page.htmlAttributes" variable, but where is that being set?
Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
Re: SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
Thanks for the quick reply, Mark.
I did see that part of the documentation, but this isn't really a multi-lingual site. I only have two pages that contain non-standard language, and I do not want the overhead of installing and administering Polylang just so I can apply the correct hyphenation styling rules on two pages.
I thought changing the locale or HTML lang setting dynamically just for those two pages would be an easy customization, but it sounds from your answer like the Gantry theme does not allow you to change from the default language.
Is there really no other option than installing Polylang?
Re: SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
Polylang is the way to go because the language is not added by Gantry but rather Wordpress translations.
There should be very little overhead by using polylang.
Regards, Mark.
Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
Re: SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
With default Wordpress themes, I can easily change the HTML lang attribute for a page using the language_attributes filter in a custom function in the theme's functions.php file.
Gantry, or at least the Helium theme, simply ignores this.
Maybe there is another way I should be implementing Wordpress filters correctly in the Gantry context?
Re: SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
I've answered this as best I can.
Changing locale in functions.php is too late. It needs to be done in a plugin - so you need to either use an existing multi-language plugin to do that for your (and we recommend polylang) or you have to write your own plugin.
Please search forums before posting. Please make sure your post includes the version of the CMS you are using and a link to the problem. Annotations on screenshots can also be helpful to explain problems/goals. Please use the "secure" tab for confidential information.
Re: SOLVED how to change the HTML "lang" attribute for a few pages only
Posted 3 years 11 months ago
Actually that's the suggestion I needed -- go ahead and set up a plugin to change locale rather than change the HTML lang attribute in functions.php.
So my takeaway is: language_attributes() filter is not supported by Gantry/Helium in functions.php. However, I can change locales for specific pages via my own plugin.