function hook_init in Drupal 7
Perform setup tasks for non-cached page requests.
This hook is run at the beginning of the page request. It is typically used to set up global parameters that are needed later in the request. When this hook is called, the theme and all modules are already loaded in memory.
This hook is not run on cached pages.
To add CSS or JS files that should be present on all pages, modules should not implement this hook, but declare these files in their .info file.
See also
Related topics
15 functions implement hook_init()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- actions_loop_test_init in modules/
simpletest/ tests/ actions_loop_test.module - Implements hook_init().
- common_test_init in modules/
simpletest/ tests/ common_test.module - Implements hook_init().
- dblog_init in modules/
dblog/ dblog.module - Implements hook_init().
- locale_init in modules/
locale/ locale.module - Implements hook_init().
- locale_test_init in modules/
locale/ tests/ locale_test.module - Implements hook_init().
1 invocation of hook_init()
- _drupal_bootstrap_full in includes/
common.inc
File
- modules/
system/ system.api.php, line 1896 - 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');
}
}