Skip navigation
Help

hook_init

6 core.php hook_init()
7 system.api.php hook_init()

Perform setup tasks. See also, hook_boot.

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.

Related topics

19 functions implement hook_init()

1 invocation of hook_init()

File

drupal/modules/system/system.api.php, line 1749
Hooks provided by Drupal core and the System module.

Code

function hook_init() {
  // Since this file should only be loaded on the front page, it cannot be
  // declared in the info file.
  if (drupal_is_front_page()) {
    drupal_add_css(drupal_get_path('module', 'foo') . '/foo.css');
  }
}