开发者

Modifying the Page Title with PHP after the fact

开发者 https://www.devze.com 2023-03-23 15:02 出处:网络
I would like to be able to change the page title with PHP. Now before you all answer with <title><?php echo $title; ?></title>

I would like to be able to change the page title with PHP. Now before you all answer with

<title><?php echo $title; ?></title>

I have a limitations... I am developing a plugin where my PHP is only inserted into the body of the page. Therefore <title> has already been defined and I would like to change it. Any ideas?

Edit: I am aware that this can be easily done with javascript. However, for SEO purposes I do not want to. I would like the actual contents of the &l开发者_运维百科t;title> tag to be modified.


<script language="text/javascript">
    document.title = '<?=$title;?>';
</script>


Insert a JavaScript snippet, that changes the title. As the if your PHP code is inserted, the header part is already streamed, so you have no way of getting that back.


You'd need echo some JavaScript that will change the title in-browser.


<script>document.title = '<?php echo mysql_real_escape_string($title); ?>';</script>

works only for js-enabled browser


You can modify it using javascript:

window.status="YourNewTitle";

Thus you can try to insert your code within a <script> tag and beg your browser to execute it when it's loaded.

0

精彩评论

暂无评论...
验证码 换一张
取 消