Change Website Title based on Page

Discussion in 'PHP' started by mokimofiki, Jul 7, 2009.

  1. #1
    I have a php website with a single header that includes the title tag. Of course what this means is that every page on my website has the same title which basically means for SEO this is a bad thing.

    Is there a way that I can tell the title to change based on the link that is clicked?

    If you don't understand my horrible explanation then basically what i'm looking for is a way to make the title different on every page when using the same header.
     
    mokimofiki, Jul 7, 2009 IP
  2. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    yes you can. there are many ways to do it.
     
    mdrobiul, Jul 7, 2009 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Yeah but how? lol I figured there was a way just need a push in a direction of how. I am pretty good with php but want a clean way of producing different titles on each page using one header.php file.
     
    mokimofiki, Jul 7, 2009 IP
  4. SHOwnsYou

    SHOwnsYou Peon

    Messages:
    209
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    example:

    in header include:

    $page = $_SERVER[PHP_SELF];
    $sql = mysql_query("SELECT title, keywords, description FROM seo WHERE page='$page'");
    while ($row = mysql_fetch_array($sql))
    {
    echo "<title>$row[title]</title>";
    echo "<meta http-equiv=\"description\" content=\"$row[description]\" />
    echo "<meta http-equiv=\"keywords\" content=\"$row[keywords]\" />
    }

    Alternatively you can just use single apostrophes and avoid all the escaping.
     
    SHOwnsYou, Jul 7, 2009 IP