hook_init

5 core.php hook_init()
6 core.php hook_init()
7 system.api.php hook_init()
8 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.

For example, this hook is a typical place for modules to add CSS or JS that should be present on every page. This hook is not run on cached pages - though CSS or JS added this way will be present on a cached page.

Return value

None.

Related topics

15 functions implement hook_init()

File

developer/hooks/core.php, line 941
These are the hooks that are invoked by the Drupal core.

Code

<?php
function hook_init() {
  drupal_add_css(drupal_get_path('module', 'book') . '/book.css');
}
?>

Comments

404 pages

You can of course use hook_init for any page not being served from cache. This includes 404 pages. http://drupal.org/node/468494#comment-1630520

And what if I need a check to

And what if I need a check to be performed on a cached pages?

page_cache_fastpath looks

ok, noticed hook_boot, will try it

Anonymous user run a page(views page) hook_init not work

I create new module have my_module_init function. Anonymous run a page (page created by views module )my_module_init not working.

hook_init only working for logged-in users?

Now working

After Disable Page cache now working good.

Login or register to post comments