Module position basics
If you've been working with Joomla, you know that a Joomla template consists of HTML and some PHP snippets.
For one, it contains a component area where the output from the different components are shown (articles, blog lists, third-party components etc). A Joomla template also contains several PHP snippets, which are called module positions. You can assign modules to these positions and they will appear in the given position in your template.
Easier way to insert scripts
Of course, you can use an extension for each third-party script you want to enter. Probably there is one available (isn't there for almost anything?). The problem with this approach, though, is that you need to keep track of X number of extensions and their updates. And for each extension you add to your site, the chance of being hacked increases. After all, code is made by humans, and humans make mistakes.
The method is simple, but effective.
You will need three module positions, and as many Custom HTML modules as you need (one for each snippet).
Inserting the module positions in your template
In order to make this as flexible as possible, you need three module positions:
Now you're ready to insert the module positions. You will need to enter the following code into your template index.php file. You'll find it here: /templates/yourtemplatename/index.php.
Make sure to create a backup of your index.php file before messing with it.
Enter this just before the </head> tag.
<jdoc:include type="modules" name="endhead" />
Enter this just after the <body> tag:
<jdoc:include type="modules" name="topbody" />
Enter this just before the </body> tag:
<jdoc:include type="modules" name="endbody" />
Save your template.
Adding the script to the Custom HTML module
I'll use Google Analytics as an example. Go to the Module Manager and click New. Choose the 'Custom HTML' module type. You will see the module parameters.
Enter a title for the module, for instance 'Google Analytics code', enable the module, choose not to show the module title.
For the Google Analytics code, we assign the module to the newly created 'endhead' position. This has the Google Analytics snippet appear just before the closing HEAD tag (</head>). As you have not entered the new module positions to the template XML file, they will not appear in the module position drop-down. Not to worry: You can simply enter the position name 'endhead' in the field directly.
Lastly, enter the HTML mode of your editor and paste the Google Analytics code into the window. You can now save the module.
Best Joomla Hosting Recommendation
ASPHostPortal.com provides our customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. We offers Joomla hosting starts from $5/month only. We also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable Joomla Hosting, we should be your best choice.