[support] Where to add items to the <head> section for all pages?

Jamie Holly hovercrafter at earthlink.net
Sun Sep 16 15:24:56 UTC 2012


A few things here:

- Theme's can override any tpl.php file. You simple copy the tpl.php 
file to your theme's directory and clear Drupal's cache and you're ready 
to change that file. This isn't "hacking core", but rather the power of 
Drupal's templating layer.

- No need for a custom module just to add javascript. The Drupal way in 
D7 for theme's to add javascript is using the .info file, so long as 
that file is to be included on every page rendered by the theme. If you 
need something more conditional, then you can use drupal_add_js inside 
mytheme_preprocess_page(). Check out the comments here:

http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7#comment-14344

- You can also use drupal_add_js() to add inline javascript. Check the 
documentation on the link above. You would want the 'inline' type of 
adding in the code.

- Whenever you add a theme override function or change the theme's .info 
file, you must clear Drupal's cache for the changes to be noticed by Drupal.

Jamie Holly
http://www.intoxination.net
http://www.hollyit.net

On 9/16/2012 6:21 AM, Dotan Cohen wrote:
> On Sun, Sep 16, 2012 at 2:39 AM, Ms. Nancy Wichmann
> <nan_wich at bellsouth.net> wrote:
> > The best solution is to include it in the (sub)theme's .info file. Next best
> > is to include it in the .info file of a custom module, if you have one. If
> > nothing else works, there is hook_init(). Never, ever, hack core.
> >
>
> Thank you, I will remember that!
>
>



More information about the support mailing list