php - How to set HTML lang attribute for different country?

I have 4 WordPress pages for 4 countries.
I want to use different HTML language attitude code for each page by one header.php
<html lang="en">
<html lang="pt">
<html lang="id">
<html lang="vi">
I tried with this code, but it's not working.
<?php
if($page == 'https://www.exmaple.com/pt') {
$language = 'pt';
}
elseif($page == 'https://www.exmaple.com/es') {
$language = 'es';
}
elseif($page == 'https://www.exmaple.com/id') {
$language = 'id';
}
elseif($page == 'https://www.exmaple.com/vi') {
$language = 'vi';
}
else {
$language = 'en';
}
?>
<!DOCTYPE html>
<html lang="<?php echo $language; ?>">
Answer
Solution:
Instead of $page try using
$_SERVER['REQUEST_URI']
It should give current URL being used.
Answer
Solution:
In code small syntax error
<html lang="<?php echo $language; ?>">
else use
<html lang="<?= $language; ?>">
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 8.0.2".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.