fbpx Query string in drupal menu items | ComputerMinds Skip to main content

Query string in drupal menu items

20th Jan 2008

Mike Dixon

Senior Mind

This was written in response to a post on drupal.org regarding query strings in drupal menu items. Currently if you create a drupal menu item linking to an external site with a querystring then this will render correctly. However if you try and use a relative URL (i.e. an internal link) then your querystring will be escaped and the URL won't work.

This override lives in your template.php file and parses all your menu paths for internal links, and will pass query strings into the l function correctly ...

function phptemplate_menu_item_link($item, $link_item) {
  if (!$item['query']){
    $parsed_url = parse_url($item['path']);
    if ($parsed_url['query'] && !$parsed_url['host']){
  return l($item['title'], 
           !empty($item['description']) ? array('title' => $item['description']) : array(),
           isset($item['query']) ? $item['query'] : NULL);