Adding JavaScript and CSS to the page

From Joomla! Documentation

Revision as of 22:26, 8 July 2008 by Masterchief (Talk | contribs)

To have a well-formed XHTML document, you must put all references to Javascript and CSS files within the <head> portion. Since Joomla! generates all of the HTML that makes up a page before output, it is possible to add these references to the <head> tag from your extension. To accomplish this, you first need to get a reference to the current document object:

$document =& JFactory::getDocument();

To add a Javascript file, use this code:


For a stylesheet, use this code:


If you want to add custom HTML to the head tag, use this code: