Dynamic title and meta tags

I am a big fan of development over parking. I am also a big fan of automating as much manual work as possible. We all have other things to do with our time besides sit in from of the computer all day or night building web pages - right ?

Dynamically create title / meta tags

Everyone wants to use unique tiles, meta keywords and descriptions on their pages. No one likes to take their site template and then modify the title and meta tags for every, single, page. We usually get lazy and use one title, keyword and description for every page but that’s not helpful for search engine relevancy, ranking or user experience.

Wouldn’t it be nice to have one file with all your title, keywords and descriptions in it? And you simply create and update that one file? And if you want to use certain page titles or descriptions throughout the rest of your site, wouldn’t it be nice to just paste a variable into an html page and have the titles or descriptions appear on a new page from your one file?

Of course it would !

The code

Here’s a few snippets of code that will make your life easier when you’re building those sites. These two files are the one file with all your meta data and a sample template to show how to use the meta data.

Meta file (you put your titles, keywords and descriptions in this file)

Template file (this is a sample template to include the data from the meta file into your web pages)

To use the code, download the two .txt files above, upload them to your web space and rename them from .txt to .php and then load the template.php file in your browser.

You will see that the title, meta keywords, meta description are dynamically inserted into the template from the meta file. You will also see that the title has been reused on the template page as an H1 heading and the meta description has been reused as a paragraph of text.

These files are samples to give you an idea of how this works. If you have any questions, feel free to place them in the comments.

I’ll do another post next time where we dynamically serve the meta data and even web pages out of a mysql database. For larger sites, you’d want to use a database to manage and server this data.

Enjoy !

Share

Trackbacks/Pingbacks

  1. [...] « Dynamic title and meta tags Bido off to a good start [...]

  2. [...] navigation and content. By using a well coded template and automating your header and footer and title and meta tags, the only work left for you to do is write [...]