Jump to content

Recommended Posts

Hey everybody:

 

What I'm trying to do is have a different title per article written on my website.  The way the site is run now, the server calls on an include file, but the browser still reads it as the title for the index.php.

 

Any ideas on how to fix this problem?

 

Regards.

Link to comment
https://forums.phpfreaks.com/topic/67139-changing-titles-with-php/
Share on other sites

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");?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.