Search code examples
phphtmlattributeslang

change html lang attribute dynamically with php


I have a web with two languages. I would like to set the attribute html lang to two languages, this is what i would like to do, however it does not work.

    if($domain == 'es') {
    $language = 'es';
    } else {
    $language = 'en';
    }
    ?>
    <!DOCTYPE html>
    <html lang="<?php $language ?>">

Solution

  • small synatx error try this

    <html lang="<?php echo $language; ?>">
    

    else use

    <html lang="<?= $language; ?>">