I have a module that loads at path module/1/view and then when user clicks a button they are redirected to another site and then redirected back to the same URL they left from with a querystring that looks like module/1/view?code=123

How do I implement a hook_menu to catch this slight difference in url/querystring param? I essentially want the hook_menu for module/1/view and module/1/view?code=123 to be different.

1 Answer 1


hook_menu() doesn't handle query parameters, so the behaviour will have to be within a single page callback.

function MYMODULE_generic_page_callback() {
  $query = drupal_get_query_parameters();
  if (empty($query['code'])) {
    return MYMODULE_without_code_page_callback();
  return MYMODULE_with_code_page_callback();

If you need dynamic behaviour for some of the other hook_menu() options, many provide a callback option. For example "title callback" would also let you use a function to change the page title based on the presence of the query parameter in the same manner as the page callback.

For access control, it's probably better to return MENU_ACCESS_DENIED or MENU_NOT_FOUND from your page callback. "access callback" will be called when rendering links to the path to determine if the user has access and the link should be shown, so the query parameter will not be available on the page that contains the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.