Drupal coder

pathauto

Pathauto improvement: a better menu trail token for deep menus in Drupal

Pathauto is one of those modules that everyone blindly installs on each of his sites. It allows you to automatically create pretty urls for all your content based on some properties of that content. Pathauto uses the Token module to allow the user to define url patterns (using the admin interface) based on tokens.

On sites with a hierarchical menu a very popular pattern (token) used is the "menupath", which is basically results into a "url-ified" version of your breadcrumb. The menupath can become very long though in case you have a deep menu structure or have a few menu items that have very long titles. Since Pathauto cuts of the long paths after a certain length (configurable via "Maximum alias length"), a lot of urls (for items deep in the menu tree) might become very similar.

One of the most important reasons for having pretty urls is search engine optimisation (SEO). But in long urls the most relevant keywords for your page are at the end of your url.

A good compromise in this case is to use only the first two (or three) menu items at the beginning of your trail and the title of the page itself. Let's see how we can build a token that we can use for our Pathauto patterns that does this. We'll call it "short menupath".

April 12, 2010Drupal, pathauto, token, url rewriting