Thursday, July 26, 2012

Include js in head tag Joomla 2.5

If you are looking for how to include javascript in the head tag of html without having to write it in the template for features like sharethis, Google analytics here is how to

Simply use the following two lines:

$document = &JFactory::getDocument();
$document->addCustomTag('<script type="text/javascript">my javascript</script>');

And it will add javascript to the head tag.

You can also include js/css files by using

$document->addStyleSheet('path');
$document->addScript('path');

2 comments:

  1. in what file to add the code you mentioned ?

    ReplyDelete
    Replies
    1. whatever you are using in views/view_name/tmpl folder.. could be default.php or some other layout file.

      Delete