I have a site that uses php includes for the <head> information for all of the pages. The problem with this is that every page is going to get the same title. Is there a way around this? I'm thinking of something like having the title pull the information out of the content somehow. Is this possible? I found a way to do it in blogger, but I know that is a lot different.
Are you pulling information out of a database or is your content just static in php pages? If you are pulling it out of a database, you can do the same for the title, meta, tags etc. If the pages are static then you can use the php variable _SERVER["SCRIPT_NAME"] and do a switch on that to create different title tags. So if you script name was "welcome.php" you could set the title to be a welcome message, and if you script name was sitemap.php you could create the title to be "site map" or whatever.
You can buffer the output and change the page title in your script: http://us3.php.net/manual/en/function.ob-start.php#53173 This function dynamically changes title of HTML page: function change_title($new_title) { $output = ob_get_contents(); ob_end_clean(); $output = preg_replace("/<title>(.*?)<\/title>/", "<title>$new_title</title>", $output); echo $output; } Example: ob_start(); // ... some output change_title('NEW TITLE!');
I tend to just have variables and common code before the include statement. Then just echo the variable out in the included file e.g. <head> <title><?php echo $PageTitle; ?></head> PHP:
So, if I put that in my included file and put something like $PageTitle = 'This page is the sitemap'; PHP: before the include, it should work right? I'm looking in to the other ways too, but they are over my head right now. I'm very new to php. Thank you for the help.
It worked perfectly. This is what I did on my title.php file that is incuded on all my pages: <?php if ( $pagetitle ) { echo $pagetitle; } else { echo "Generic default title here"; } ?> PHP: This way I will still have the generic title on all my pages until I can get the $pagetitle="new title here"; PHP: on all my pages. Thank you. This was my first php other than include.