In my custom Drupal 7 module I am using CUSTOM_MODULE_NAME_init() function. But it is not triggered while page execution. Any suggestions?

  • 1
    you'll get better answers if we can see your code. try gist.github.com or drupalbin.com Commented Aug 23, 2011 at 11:39
  • I'm not sure if this will apply to you, I am running Drupal 6, but my problems with this were fixed when I adjusted the module weight in the system table in the DB.
    – AllisonC
    Commented May 25, 2018 at 13:21

3 Answers 3


Hook implementations are cached in Drupal 7. After implementing a new hook, you need to clear the cache. See What method is used to clear caches in the Drupal? for ways to do that.

  • Yes. I cleared the cache. But not invoked
    – Vinoth
    Commented Aug 23, 2011 at 10:28
  1. Make sure that the module is enabled (don't laugh, I forget that sometimes).
  2. Make sure that the page is not served from cache. Use hook_boot if you need to perform setup tasks for cached pages.
  3. Use a debugger to step through the execution. hook_init is invoked at the end of _drupal_bootstrap_full.
  • How to debug the execution?
    – Vinoth
    Commented Aug 23, 2011 at 10:28
  • Caveman debugging: put print_r statements at relevant places of the code to get feedback about which parts of the code are executed and what values the variables hold. Because this is tedious if done often, a better solution is to install a debugging extension on the server, e.g. Xdebug and using an IDE that can controll the debugger, e.g. Eclipse PDT.
    – Oswald
    Commented Aug 23, 2011 at 10:40

As reported in the documentation for hook_init(), the hook is not invoked on cached pages. This means that, if the content of a page is found in cache, the hook implemented by your module is not invoked.

This hook is run at the beginning of the page request. It is typically used to set up global parameters which are needed later in the request. when this hook is called, all modules are already loaded in memory.

This hook is not run on cached pages.

To add CSS or JS that should be present on all pages, modules should not implement this hook, but declare these files in their .info file.

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.