Hi 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?
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.
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):
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
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
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
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.
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.
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.