4.6.x core.php hook_init()
4.7.x core.php hook_init()
5.x core.php hook_init()
6.x core.php hook_init()
7.x 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()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

aggregator_init in modules/aggregator/aggregator.module
Implementation of hook_init().
blogapi_init in modules/blogapi/blogapi.module
book_init in modules/book/book.module
Implementation of hook_init(). Add's the book module's CSS.
conf_init in includes/bootstrap.inc
Loads the configuration and sets the base URL, cookie domain, and session name correctly.
dblog_init in modules/dblog/dblog.module

... See full list

1 invocation of hook_init()

File

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

Code

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

Comments

coltrane’s picture

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

int_ua’s picture

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

int_ua’s picture

ok, noticed hook_boot, will try it

balaji88ee’s picture

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?

balaji88ee’s picture

After Disable Page cache now working good.

srees’s picture

...because I can't figure out why my nodeapi hook is getting called before hook_Init. WTH is up with that.