Change document title

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wheatleyweb
Forum Newbie
Posts: 6
Joined: Wed Jan 14, 2009 11:02 am

Change document title

Post by wheatleyweb »

Hello all,

Nooberiffic here. Just trying to utilize PHP for the first time. I'm not doing anything "real php-like" at this point. Having a bit of a problem using the include construct, and page titles. So I'm building a site utilizing include to append the header and footer to each content page. Working wonderfully.

However, I'm implementing site search functionality via "free find" and I'm having an issue with the returned results. They all have the title defined on header.php. The search results are correct and works wonderfully, it just doesn't look appealing when every result has the same title. So I first tried to tackle this in JS and it worked to change the title onload of each content page, but not in the results. So then I tried to tackle this via PHP and thought I had something that would work, but I can't seem to make it happen. Any light you guys could shed on this would be much appreciated. This is my first attempt with PHP and the site is not DB-driven.

Here is the PHP I've tried...

...in header.php...

Code: Select all

<title><?php echo $pageTitle?></title>
...in each content.php...

Code: Select all

<?php
$pageTitle = "Whatever you want the page title for this page to be";
?>
The result is an empty <title></title>

Thanks again

wheatleyweb
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Change document title

Post by requinix »

content.php needs to include header.php after it defines $pageTitle. Have you done that?
wheatleyweb
Forum Newbie
Posts: 6
Joined: Wed Jan 14, 2009 11:02 am

Re: Change document title

Post by wheatleyweb »

Perfect! I had just figured it out. Just put it together that I had the include before defining the variable. Man I'd been struggling with that for days.

Thanks for the quick reply.

I can't wait to dig in deeper to this language.
Post Reply