The Lodge is members-only design/dev videos and Office Hours.

Next Office Hours Session: "Implementing an SVG Icon System" Nov 30 - 6:00 PM Eastern

[php] html "lang" attribute if statement

  • # May 16, 2010 at 2:20 am

    So I am using wordpress with a multilingual plugin. In the english and spanish it gives the html tag an attribute of lang.

    So if its an english page it would look like this:
    <html lang="en">

    And if its a spanish page it would look like this:
    <html lang="es">

    So in my header I want to add a php conditional statement that looks something like this:
    <?php if(lang="es") {
    echo ‘[english html code]’;
    } else {
    echo ‘[spanish html code]’;

    Of course that is wrong but how would I so this correctly? Thanks!

    # October 12, 2012 at 6:55 am

    I tried searching for this too but there doesn’t seem to be a way to detect the actual website lang attribute, only that of the browser which is no help.

    If you’re using the qTranslate plugin, or another one, look into the code and see how they detect the selected language. Might be a cookie or session. Then you will have a starting point

    # October 12, 2012 at 9:41 pm

    This reply has been reported for inappropriate content.

    the language is probably being detected from the HTTP Accept-Language header, which is accessible from PHP in $_SERVER.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed