I have a module with a menu hook that I want to give access to everyone. At first I had simply

function hook_menu() {
  $items['site_search'] = array(
    'page callback' => 'my_callback',
  return $items;

But when I navigated to /search, I got a warning that I didn't have permission. I thought I had remembered somewhere along the line that I could do 'access callback' => TRUE, in the menu hook to allow anonymous access, but that doesn't seem to work either.

Do I really have to add another function that just returns true to use as the access callback to give anonymous users access to this path?


You can definitely set 'access callback' => TRUE on the menu item and that will bypass any access checks, you don't need to implement a function that just returns TRUE (it would be redundant). Don't forget you need to clear the caches before changes in hook_menu will get picked up though.

Rather than just blindly returning TRUE though it's probably a better idea to assign a permission to the anonymous user role, or piggyback off of one that's already there (access content is the usual suspect for this if it fits in with your workflow). You can do that by using 'access arguments' => array('access content') instead of 'access callback' (don't use both).

Also you've missed out the title in your example, according to the docs that property is required. I doubt that's actually causing the problem though.

Just on another note, you mention that you're visiting '/search' to test this page - the path you've defined will be at '/site_search' instead.

| improve this answer | |
  • You're right, it does work. Forgot to clear the cache :P – user1359 Nov 7 '12 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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