Includes and seo

In many cases the title will be representative of the main content for the page. Take a blog posting my example. Ideally the title of the page should include in some manor the title of the blog post. Just look at the title of this thread by example. The title includes the thread title alongside the name of the site. Its very rare unless working on a fairly small and insignificant site that the title for each separate piece of main content will be the same. The title should always in some manor include information about the main content displayed on the page. The main content will generally dictate the meta data.

If you were defining the title and meta tags for each page (writing them seperately on each relevant page), what would you be varying…?

Like oddz said, the title and meta description should relate to that particular page.
So what’s your reason for having a different page? It must have different content than some other page on your site, or it wouldn’t exist.

The <title> is the title of that page. Not your whole site. Same with meta description.

Thanks for your help

Im only confused with this part though

“BUT the title, and meta description is unique to each page, so you’d define it there, and pass it in to that class to vary the output for each page.”

LIGHTNING BOLT! I think Ive got it. I actually forgot the HTML is part of an include and the title and meta tags ‘values’ are variables which change according to the page.

Each page might perhaps have a variable name of ‘$title’ but you would write its values at the top of that page. Obviously this would change form page to page.

If I am right then Ive just completely over-complicated myself and forgotten both methods use includes. If I am wrong however then testing the gravity between my window and the downstairs might be an option.

Gravity is 9.8ms^2, so don’t worry about that.

And yes, the purpose of the include is to provide the structure of the common page elements, while allowing you to pass in the data that is page specific.

So the Doctype is the same for all pages, it is hard-coded into my pageElements class. The title however is variable, so you pass in the value from the page. The page knows what it’s title should be. The class will append the site name if it’s not already part of the string.

The meta description is variable, so again, you pass it in.

Have a go at running the code in my early post (#6). You’ll need PHP5.
Save the first block of code as a file (an include). Then in another file, include that script and pass in the title and meta description like my second block demonstrates. View the resultant source code in your browser and you should see what it outputs.

You can change the markup in PageElements to suite (e.g. change the HTML5 footer element into a DIV). By looking at the output source code you should see how it works though.

Thanks Cranial

I’m gonna try and give it a go today and Ill post and let you know what happens (stand back!)

I havent got as far as classes yet, only the pure minimum so gonna crack on with those too

Thanks again

Think I may have underestimated how long OOP might take to learn lol

Better crack on with everything :slight_smile:

I can not see the point of your method cranial-bore. If you need to write the title etc. into a variable on every page why not just do it in the header anyway?

If you decide to change the title or metatags on more than one page you need to open every page rather than do it all in one place.

Anyway each to their own method.

But the titles are supposed to be different on every page. So saying you need to open every page is true, but logical. If you needed to change the content for your whole site, you’d need to open every page too. I don’t think there are practical benefits to defining every title and meta description for your whole site in one file.