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.

Header title tag issue

Discussion in 'HTML & Website Design' started by canalboatman, Oct 12, 2008.

  1. #1
    Hi
    SEMrush
    My header is a separate .html page which is attached to all my pages using a php tag at the top of each web page thus:
    (<?php
    $page_title = 'RBS Home';
    include ('./includes/RBS2_header.html');
    ?>
    It works fine, but this means that the <head> of all my pages is contained in that header. Therefore search engines like Google pick up the same title tag for each and all of my pages. This shows up in their webmaster tools as a title tag issue. Is there any way round this, without abandoning my use of php?
     
    canalboatman, Oct 12, 2008 IP
    SEMrush
  2. Stomme poes

    Stomme poes Peon

    Messages:
    3,195
    Likes Received:
    136
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think each page will have to get a different include-- since each page not only gets a different title, there should also be a different meta description tag as well, and possibly if your header include went from opening <!DOCTYPE declaration all the way to the opening <body> tag you could also have different body id's or classes which also go with the new title and description.
     
    Stomme poes, Oct 12, 2008 IP
  3. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im pretty sure that I have misunderstood your problem but here goes nothing:

    Why not make the header.html a php file and then echo out the page title, like so,

    
    <?php
    $title = "A unique title for each page";
    include("path/to/file/header.php");
    ?>
    
    Code (markup):
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <title>
    <?php echo $title; ?>
    </title>
    </head>
    <body>
    
    Code (markup):
     
    nicangeli, Oct 12, 2008 IP
  4. canalboatman

    canalboatman Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That is an interesting idea and I'm trying to get my head around it (I've learnt what I know as I've needed to by ploughing through books and stuff so my php knowledge is far from extensive). The second bit of code presumably goes - has to go - at the start of my existing header .html. In fact, as I write this, that seems to make complete sense.

    Sorry if this sound thick, but where do I put the actual individual title for each page that will echo into the header.php (as it will now become?

    Thanks for your help - there's a virtual pint in it!

    Dominic
     
    canalboatman, Oct 13, 2008 IP
  5. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    OK,

    Say for example you have your index.php file, (the home page). It may look like this,

    
    <?php
    $title = "The index Page (The home Page)";
    include ("header.php");
    ?>
    <h1> The home page </h1>
    <?php include ("footer.php"); ?>
    
    
    Code (markup):
    Then you would need to have a header.php and a footer.php file (stick with me!). They would look like,

    header.php
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <title>
    <?php echo $title; ?>
    </title>
    </head>
    <body>
    
    Code (markup):
    footer.php
    
    </body>
    </html>
    
    Code (markup):
    Then if you were to (say) open the index.php file in your browser (once uploaded and everything) you will see that the html looks like so,

    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <head>
    <title>
    The index Page (The home Page)
    </title>
    </head>
    <body>
    <h1> The home page </h1>
    </body>
    </html>
    
    Code (markup):
    Notice how the echo $title is replaced with whatever you defined it as in index.php

    You could then for example have another file called shop.php which may look like,

    
    <?php 
    $title = "Start Shopping now";
    include("header.php");
    ?>
    <h1> Start shopping, its fun! </h1>
    <?php
    include ("footer.php");
    ?>
    
    Code (markup):
    What would the HTML look like? Notice how any variables that are defined in one file can be used by any file that is included.

    Nick
     
    nicangeli, Oct 13, 2008 IP
  6. canalboatman

    canalboatman Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Brilliant. I understand all of that, and already have a header and footer.php file. But I'd not thought of replacing the <title> in the header.php with a php request.

    I'm sure it work - can't see why not - so thanks a lot mate.

    Make that 2 virtual pints:)

    Dominic
     
    canalboatman, Oct 14, 2008 IP
  7. Vozzek

    Vozzek Active Member

    Messages:
    206
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Nicangeli's example is exactly how I do it, and it works extremely well. It's neat, it's easy, and everything looks great in google's webmaster tools. If you're not already doing it this way, I recommend it.
     
    Vozzek, Oct 14, 2008 IP
  8. canalboatman

    canalboatman Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Indeed it does. I've just applied it to all my pages. Easy when someone points you in the right direction, and it had been annoying me for weeks. Thanks once again Nicangeli and thank you too, Vozzek.
     
    canalboatman, Oct 14, 2008 IP
  9. Vozzek

    Vozzek Active Member

    Messages:
    206
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #9
    Not a problem bro. Make sure you vary your description tags too. I use a $desc variable much the same way, and if I know the page is going to be repeated (though parameter passing in the URL or whatever) I find some way to vary it even slightly by using PhP. Unique content is king.
     
    Vozzek, Oct 14, 2008 IP