When using a MVC(P) framework most of those things that appear in the header can be set at any point within the request before the HTML is output to page. That said most meta tags are worthless. I’m far from a SEO snake, but that is what I have been told/heard.
I agree meta keywords are pretty much outlawed due to spam.
I’m sure your ways are alot better. The switch statement might be something I could write.
The function or method for the header sounds very interesting but to be honest I would have no idea what a method is…
Could you perhaps post some example code to assist me in writing my own…?
A method is just a function of a class.
So you could have a page template class and have methods for header and footer.
I also define paths to CSS/JS files. That way a given page can request the files it needs and avoid having unnecessary scripts loaded on every page. When those files change I can also update the file name (to force a fresh download and avoid cache issues) and it’ll work across the site.
The search engine crawler cannot see the PHP code or anything else that parses server side. Includes are parsed server side and delivered to the outside world. There is no way for the spider to know whether the file was dynamically generated or not.
This is gonna sound really amateur, the switch codes you have, one for index and for one contact do you add each case to each page individually or keep them in an include and call them…?
I can see you echo title and the meta tags in the HTML but how does the page know which case to use…?
// Get the name of the page for the switch statement
$path_parts = pathinfo($_SERVER['PHP_SELF']);
$filename = basename($path_parts['basename']);
The current page name is now in $filename. That is used to select the correct section of switch and you add as many switch statements as you have pages.
You can add a echo $filename to see what it contains before the switch comand to confirm you are doing it correctly and remove it when the code is working OK.
Also, rather than having a Switch statement with ‘x’ number of metatag descriptions on it which would be lots of lines of un-needed code, why not (if you have it) save the titles, desciptions, keywords data in MySQL and dynamically call each pages data out depending on what page you are on.
That does sound really productive, I was just wondering does that work ok with how the spiders crawl and how Google indexes, the same point Michael Morris wrote about a few posts back…?
I don’t like the idea of having all the meta data for your whole site in one file, especially when tied to the base file name. What if one script can serve variable content? I’d rather pass the data in from each page, or if it’s DB driven content store it there and pass to the page template.
As for what how search engines index-- They don’t see your PHP. They don’t know how you structure any of this. That is SERVER side code. They see your URLs, and the HTML your script outputs. If you want to know what they see, view the source of the page in your browser.
ahh ok so the php will output the relevant HTML therefore it can be indexed and swept through by the spiders.
When you say from each page, do you mean write the php on each page or call it from an include…? As you can see Im still very far behind from figuring out your code lol
Calling it from the database sounds like a good idea, is that as reliable though…?