Skip to content

CakePHP plugin to simplify/automate basic SEO tasks (slugs, title, meta...)

Notifications You must be signed in to change notification settings

sbuzonas/CakePHP-Plugin-Seo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

/*
 * SEO CakePHP Component
 * Copyright (c) 2008 Matt Curry
 * www.PseudoCoder.com
 * http://github.com/mcurry/seo
 *
 * @author      Matt Curry <matt@pseudocoder.com>
 * @license     MIT
 *
 */

/* About */
	The intent of this component is to automatically set relevent page titles and meta descriptions
based on the content being sent to the view.  It also assists in make pretty urls.

/* Notes */
  * This component is in a very early state.  It probably won't work automatically in your application.
  * Patches for supporting a larger application base are appreciated.

/* Instructions */
  1. Include the component in your app controller:
    var $components = array('Seo.Seo');
  
  2. The component will automatically try to pull relevant information for the title/meta description from:
    a. $Controller->data
    b. $Controller->viewVars
    
  3. In your view the meta description is assigned to $meta_description_for_layout.
  
  4. The page title will be $title_for_layout (CakePHP standard);
  
  5. There is also a 2nd class "Seo" which has a static function for creating pretty urls.
     Say you were making a link to view a blog post and you wanted the link to be
     "/posts/view/12/this-is-the-blog-post-title" you would create the link:
     $html->link($post['Post']['name'], array('action' => 'view', Seo::slug($post['Post'])));
     The url function will automatically pull the id and title from $post and create the link.
  
  6. In your controller you can leave the view function as is "function view($id) { ... }".
     CakePHP will automatically populate the $id and ignore the extra title param.
		 
	7. If you are worried about slug consitency you can use the verifySlug which will force a 301 redirect if the slug doesn't match.
		function view($id, $slug=null) {			
			$post = $this->Post->read(null, $id);
			$this->Seo->verifySlug($post);			
			$this->set('post', $post);
		}
	
/* Short Urls */
	If you need to post a link on twitter or some other service with limited characters simply remove the slug part of the link.
	For example: "/posts/view/12/this-is-the-blog-post-title" to "/posts/view/12"
	
/* Even Shorter Urls */
	Since the component works with Cake's built in routing system you can add a route like:
	Router::connect('/p/*', array('controller' => 'posts', 'action' => 'view'));
	All your links will be generated as: "/p/12/this-is-the-blog-post-title" and you can use "/p/12" as a short link

About

CakePHP plugin to simplify/automate basic SEO tasks (slugs, title, meta...)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published