I'm using Drupal 7, Views 3, and hook_menu_alter

function MYMODULE_menu_alter(&$items){
  $items['client/place/%'] = array(
    'access callback' => 'custom_function',

to override the view visibility (access), also flushing caches, but this doesn't seems to work, can somebody give some light about how to solve this, is this the right way to override path defined by a view ?

thanks in advance

  • 1
    I think you may have made a typo there; your question says "access callback" while your sample code sets the "page callback". Commented Mar 13, 2013 at 22:24
  • You are right. I just updated it
    – mauricio
    Commented Mar 14, 2013 at 15:13

1 Answer 1


Reminder: Views module allows you to set the access from Views UI

If you want to create your own logic; this is how your code should look like:

function MYMODULE_menu_alter(&$items){
  $items['client/place/%']['access callback'] = 'MYMODULE_custom_callback'; 

function MYMODULE_custom_callback(){ 
  $isValid = false;

  /* your logic */

  return $isValid;

Make sure your module is called after the Views module. Usually Views module wight is 10; so your module wight should be 11 or more.

Also, don't forget to clear your cache.

  • 1
    hello, thanks. It works. I need more than per role or permission filter (as through views UI). I've searched looking for a way to know which is weight module, here are some methods http://drupal.org/node/110238.
    – mauricio
    Commented Mar 14, 2013 at 16:19
  • you're welcome, glad it worked for you.
    – Aboodred1
    Commented Mar 14, 2013 at 16:22
  • 5
    It's also possible to use hook_module_implements_alter to move your hook_menu_alter implementation after Views, and then see the menu items Views has added. Works about the same as setting the module weight, except you don't have to set an explicit weight for your module.
    – thirdender
    Commented Jun 22, 2014 at 10:27
  • 1
    I had to use %views_arg instead of % for it to work for me. So like this: $items['user/%views_arg/posts']['access callback'] = 'MYMODULE_custom_access_callback';
    – jphelan
    Commented Jan 20, 2017 at 22:21

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.