cakephp logo

SEO meta tags under Cakephp 1.2

Setting your pages meta tag keywords and description is simple under CakePHP 1.2, all one needs is the Html Helper's meta() function. Probably the easiest way is to see how its done is with an example, this code is added to your view files :-

Show Plain Text
PHP code
  1. echo $html->meta('keywords', 'your keywords goes here', array('type' => 'keywords'), false);
  2. echo $html->meta('description', 'your description goes here', array('type' => 'description'), false);

In my original article on meta tags I ended up setting a variable in the view and checking for the variables in the default layout file. I had tried the $html->meta() function originally but couldn't get it to work and didn't have time to figure things out.

It wasn't till I was trying to get some javascript code to output into the head section from a view using the $this->addScript() function that I realized I didn't have the echo $scripts_for_layout line in the default.ctp layout.

Not sure when or how I deleted it but in the words of Homer Simpson all I can say is DOH.

Update: 2 Dec 2008, I see an example of meta() function is now documented in the CakePHP book, please refer to this page

Notice (8): Use of undefined constant target - assumed 'target' [APP/views/posts/view.ctp(51) : eval()'d code, line 8]
Inserting-Well-Formatted-elements

Filed under: Cakephp  Tags: Seo

3 Responses to “SEO meta tags under Cakephp 1.2”

Thanks fellow developer, I'm on a time crunch and this was a little piece of treasure in the form of a blog post that came up on google. You rock!

So would I take it that we would write this into the View?

@Chris C2 Yes that is correct Chris you can place the code in your view or set a variable in the view which is passed to the layout which runs the meta code

Post a comment