Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to overwrite a page's <title> tag by using PHP within the body?

Tags:

php

I'm pretty new to PHP and was wondering if there was a way to overwrite what is displayed in a title tag by using PHP inside the body.

Let me explain why I'm trying to do this. I'm using a forum/cms software that allows me to create PHP pages, but won't let me change anything about the header (including the title tag). I was hoping there was a script that I could place into the body using PHP that would overwrite whatever was displayed into the default title tag.

This is probably a crazy question, and if so I apologize.

Just running out of ideas how to get what I need in the title.

Thanks!

like image 721
rngrdanny22 Avatar asked Apr 14 '13 23:04

rngrdanny22


2 Answers

You can't.

if you want to change it add some Java Script code that will execute on the client side and do this for you:

 <script>
 document.title = "This is the new page title.";
 </script>

And with some PHP:

<head><title>some title</title></head>
<body>
   <?php if (some condition, etc) { ?>
   <script>
        document.title = "This is the new page title.";
   </script>
   <?php } ?>
</body>
like image 65
Amirshk Avatar answered Oct 17 '22 22:10

Amirshk


<html>
    <head>
        <title>Hello</title>
    </head>
    <body>
        <?
            echo "<script>document.title='Hello, World!';</script>";
        ?>
    </body>
</html>
like image 2
Hanlet Escaño Avatar answered Oct 17 '22 21:10

Hanlet Escaño