[英]How to set HTML lang attribute for different country?
I have 4 WordPress pages for 4 countries.我有 4 个国家/地区的 4 个WordPress页面。
I want to use different HTML language attitude code for each page by one header.php我想通过一个 header.php 为每个页面使用不同的 HTML 语言态度代码
<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; ?>">
Instead of $page try using而不是 $page 尝试使用
$_SERVER['REQUEST_URI']
It should give current URL being used.它应该给出当前正在使用的 URL。
In code small syntax error在代码小语法错误
<html lang="<?php echo $language; ?>">
else use否则使用
<html lang="<?= $language; ?>">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.