简体   繁体   中英

How to maintain a dynamic page title with valid markup?

Currently in my code I have something like this outside of the HTML head tag:

<title>My Website - <?php echo $row['title']; ?></title>

This works but does not validate with w3 because with XHTML titles can only be modified within the HTML head tag.

How does one solve this? I want to maintain 100% valid XHTML Strict markup which I currently have but I don't want to use any messy hacks either. I read that changing the website title with Javascript after the page loads is bad practice but it seems like the only viable option here. What does SO think?

如果您粘贴在PHP完成执行后呈现的HTML(在验证器中),则应该正确验证(假设您将标题标记放在正确的位置[又名<head></head>标记])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM