I have module which i want to run on every page. How can i do that? And for later use: how to run module on specific pages?

Comments

redsd’s picture

You could use hook_init http://api.drupal.org/api/drupal/modules!system!system.api.php/function/...

An easier way would probally to create a block, and just load that block through drupal admin, there you can config on which pages to load.

http://drupal.stackexchange.com/questions/5582/easy-way-to-create-blocks...

mustikka’s picture

Thanks! It works.
Now i have another problem. What form i should return my function data from hook_init() ? Because:

hook_init() {
return functionname();
}

doesn't work.
Called function returns modal window.

redsd’s picture

Do you want to add content to all the pages, or javascript or do you just want to call a function of yours?

if you want to add content to all pages, you are better off using hook_page_alter or hook_page_build I think.

mustikka’s picture

I want to add piece of JavaScript, if conditions match. So I used hook_page_alter to add a piece of JavaScript to the page, if necessary.
Thanks for your help!

redsd’s picture

Your welcome,

if the problem is solved you could change the subject title and add [solved] to the front.