[wp-hackers] Permalink Structure - Performance vs. SEO

Mike Schinkel mikeschinkel at newclarity.net
Sun Jun 12 06:10:02 UTC 2011

Hi Leo,

Yes, by default WordPress cannot handle the URL structure of "category_name/name" without potentially having serious performance issues, but it is possible to handle the routing yourself for those URLs and then it can be sufficiently performant, especially if you use caching for the category slugs and for the most frequent URLs. 

The basic approach is to subclass the WP class (call it Leos_WP?) and in a "setup_theme" hook replace the $wp instance with an instance or your subclass like this:

global $wp;
$wp = new Leos_WP(); 

You also override the parse_request() method in Leos_WP and in it test $_SERVER['REQUEST_URI'] to see if it contains a valid "category_name/name" and if so then set $name to have the post slug and set the following:

global $wp;
$wp->query_vars = array('name'=>$name);

If it doesn't match "category_name/name" then just delegate back to the parent parse_request().  This is where your caching of the list of categories can come in handy.

You will also want to use the 'post_type_link' hook to ensure WordPress displays the proper URL for posts.  One issue will be you'll need to pick a primary category for a post's URL if there are more than one category assigned to the post.  

I've got this implemented in a more complex setup so I know it works well.  If you want to attempt it and have additional questions, just ask.

NOTE: I would be cautious to include this solution in a plugin that you plan to distribute because it would be incompatible with any other plugin that decides to use this same technique.  Of course if the WordPress team were to add the hook requested in ticket #16992 then this technique could easily be used in a plugin without concern, and also without having to subclass the WP class:


Hope this helps.


On Jun 11, 2011, at 9:01 PM, Leo Baiano wrote:

> I have a question ... Working in a large project site and will have many
> pages, so I opted for the permalink structure that shows the year before the
> name of the post, did it to improve the performance of WP.
> The problem is that the analyst SEO project asked me to use the category
> structure / name of the post, I explained that this causes WordPress to
> create several lines of rules to be more than normal and can severely damage
> the site in terms of performance, since whenever a URL is requested the WP
> need to read a lot of rules to find how to handle the URL, but he claimed
> that putting the loss of performance and loss of points in the optimization
> SEO SEO ending balance weighing more.
> Ask references about the interference of the URL in the site optimization
> but he has not handed me anything, so I come to exchange experience with you
> on the subject, have done so? Actually the structure category / name of the
> post instead of year / name of the post will greatly influence the
> positioning of pages in search engines?
> -- 
> Amplexos,
> Leo Baiano
> http://www.leobaiano.com
> http://www.blog.ljunior.com
> http://www.mcelebridades.com
> http://www.twitter.com/leobaiano
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list