Search Engine Optimisation (SEO)
Archived posts from this Category
Archived posts from this Category
Posted by admin on 04 Jun 2008 | Tagged as: Search Engine Optimisation (SEO)
It’s quite well known that the title element in a page helps with SEO, it helps identify to search engines and users what your page is about. But how exactly do you do this if you use a PHP include to include a common page header across multiple pages?
If you have a static page it’s as easy as just a simple:
But if you were to save this as ‘header.html’ and save it in a templates directory and included it in every php page using
Then every page would have the same page title: “How to peel a Banana”.
The solution is quite simple but sometimes overlooked.
All you need to do is this:
We first rename our page to header.php and open our file for editing.
We can then use php to echo a variable that will contain our page title. We will add the page title to the page that we use the include in later on. So how do we do this? we use a simple php
isset()
function to enter our page header. In this way, the header page will not generate any errors if we decide to not provide a page specific title for any given page.
I often find it is useful to have the site title in the page title also, say our page belongs to the website ‘allaboutbananas.com’, so we can add this into our header template.
Then, when we publish a new page on our site we include the optional dynamic page title like so: