0
Welcome Guest! Login
0 items Join Now

SOLVED how to change the HTML "lang" attribute for a few pages only

    • minbori's Avatar
    • minbori
    • Jr. Rocketeer
    • Posts: 21
    • Thanks: 0

    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?

      Any tips on how I might do this?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    Re: SOLVED how to change the HTML "lang" attribute for a few pages only

    Posted 3 years 11 months ago
    • If this is a mono-lingual site then you just change the language in the Wordpress settings. If it's a multi-lingual site then see these docs http://docs.gantry.org/gantry5/tutorials/multilingual-site-wordpress .

      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.
    • minbori's Avatar
    • minbori
    • Jr. Rocketeer
    • Posts: 21
    • Thanks: 0

    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?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    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.
    • minbori's Avatar
    • minbori
    • Jr. Rocketeer
    • Posts: 21
    • Thanks: 0

    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?
    • MrT's Avatar
    • MrT
    • Preeminent Rocketeer
    • Posts: 101084
    • Thanks: 13484
    • Web Designer/Developer

    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.

      See https://wholesomecode.ltd/blog/wordpress-site-language-dynamically/

      Regards, Mark.
    • The following users have thanked you: minbori

    • 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.
    • minbori's Avatar
    • minbori
    • Jr. Rocketeer
    • Posts: 21
    • Thanks: 0

    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.

      Thanks again for your time.

Time to create page: 0.096 seconds