Jump to content

Changing Titles with PHP


tothemax

Recommended Posts

your need to do something like this.

JS

echo "<script language='javascript'>document.title = 'NewTitle';</script>";

 

or

PHP/HTML

1. create a header file (header.php)

<?php
function newheader($title){
if(empty($title))
{
$title="default page title";
}
echo "<html>";
echo "<head>";
echo "<title>$title</title>";
echo "</head>";
} ?>

 

2. add at the top of your affected files

<?php
require_once('newheader.php');
newheader("TheTitle");?>

I'm the person that put tothemax's site together.  I'm not that proficient with PHP, not a novice, but not an expert either.

 

I developed the site using PHP includes.

 

<?php if ($area) {include("content_includes/$area.inc");

  }

  ?>

 

$area is defined at the top of index.php:

 

<?php if ($_GET['area']) {

    $area = $_GET['area'];

} else {

    $area = "home";}

?>

 

The dilemma is that search engines aren't too friendly with includes, so we changed the pages dynamically through the htaccess file.  Which worked alright, but the title section only displays what is on the index.php page.  Is there a way to call the section title, in each include file, to the title tag in the head section of index.php?

 

I hope I haven't confused any of you.  I think I've confused myself.

You rule!  I'll test these methods out and let you know how it worked.

 

Thanks so much.

 

your need to do something like this.

JS

echo "<script language='javascript'>document.title = 'NewTitle';</script>";

 

or

PHP/HTML

1. create a header file (header.php)

<?php
function newheader($title){
if(empty($title))
{
$title="default page title";
}
echo "<html>";
echo "<head>";
echo "<title>$title</title>";
echo "</head>";
} ?>

 

2. add at the top of your affected files

<?php
require_once('newheader.php');
newheader("TheTitle");?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.