1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Include Header... But Different <title></title>?

Discussion in 'PHP' started by scottlpool2003, Dec 4, 2007.

  1. #1
    Greetings!

    On my websites I use the same header for each page by

    <?php include"includes/header.php";?>
    PHP:
    But I really need to SEO by having different titles...

    Do you know how I can do this?

    I'll be forever grateful, as this will save me a lot of time having seperate headers for each page!

    Regards,

    Scott.
     
    scottlpool2003, Dec 4, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes you can do it, but one would need to look at complete code...

    One solution would be to set $title = "Custom Page Title"; before including header file.

    In the header you could then have ....<title>$title</title>...

    Like i said, it mostly depends on what you already have, how it is programmed, then you modify it accordingly.
     
    hogan_h, Dec 4, 2007 IP
    scottlpool2003 likes this.
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    I'm not too familiar with PHP coding.

    My websites are all in HTML, the only PHP coding I use are includes and SQL queries.

    How would I go about config'ing the PHP to include $title?

    Would it be something like:

    <?php
    $title = "";
    ?>
     
    scottlpool2003, Dec 4, 2007 IP
  4. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #4
    scottlpool2003, Dec 4, 2007 IP
  5. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    On every page, existing header include code you could replace with:
    
    <?php
    $title = "Page1 Title";
    include"includes/header.php";
    ?>
    
    Code (markup):
    In your header.php, if you have something like this: <title>Old Same Title</title> you replace it with:
    
    <title><?php echo $title; ?></title>
    
    Code (markup):
    Even better would be:
    
    <title><?php if (isset($title)) echo $title; else echo "Old Same Title"; ?></title>
    
    Code (markup):
    That way for the pages where you still didn't get to set the custom title, it would display the "standard" one.
    Whole code is not pretty, but it's probably the way you already have it and it would work ;)
     
    hogan_h, Dec 4, 2007 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #6
    That worked.

    Anyone else looking for a solution to this problem. It's simple.

    Start your page with:

    And then your title tags should be as followed:

    Same for other things such as:

     
    scottlpool2003, Dec 4, 2007 IP
  7. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #7
    Thanks Hogan_h.

    I did look for a similar thread but couldn't find one.

    Thanks a lot!

    Scott.
     
    scottlpool2003, Dec 4, 2007 IP
  8. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You are wellcome ;)
    I would still suggest using:
    
    <title><?php if (isset($title)) echo $title; else echo "Old Same Title"; ?></title>
    
    Code (markup):
    especially if you have many pages and can't change them all at once, then you could modify them one by one without breaking the title name on any page.
     
    hogan_h, Dec 4, 2007 IP
  9. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #9
    So you mean if I use that code...

    I leave this blank:

    <?php
    $title = "";
    include"includes/header.php";
    ?>

    It will echo "same old header".

    That's even better!

    Thanks dude.
     
    scottlpool2003, Dec 4, 2007 IP
  10. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #10
    Got it...

    That worked thanks a lot!

    +REP :)

    Scott.
     
    scottlpool2003, Dec 4, 2007 IP
    hogan_h likes this.
  11. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #11
    In that case no, it would only work if there is no $title at all before including the header.php

    If you set $title to anything else, even if it's "" (empty string) then it will output that and not the "standard title".
     
    hogan_h, Dec 4, 2007 IP
  12. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I see that you found a solution.

    I actually use a different solution to accomplish the same thing if interested.

    My header is in a function.

    
    
    function ShowHeader($Title,$MetaDesc){
    $DefTitle = "Show me when title is blank";
    $DefMetaDesc = "Show me when Meta Desc is blank";
    if($Title=="")$Title=$DefTitle;
    if($MetaDesc=="")$MetaDesc=$DefMetaDesc;
    //header stuff goes here
    }
    
    
    PHP:
     
    imvain2, Dec 4, 2007 IP
  13. phpl33t

    phpl33t Banned

    Messages:
    456
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #13
    use a plugin based template class. Including headers and footers is very noobish.
     
    phpl33t, Dec 5, 2007 IP
  14. imvain2

    imvain2 Peon

    Messages:
    218
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I would have to disagree with the noobish statement.

    Just because people subscribe to the KISS principle doesn't mean they are noobs.

    Plugin based templates will work just fine, but for most projects it is simply over kill.
     
    imvain2, Dec 5, 2007 IP
    vertigoflow likes this.