-
AuthorPosts
-
Manos Moderator
Manos
- Join date:
- February 2014
- Posts:
- 2806
- Downloads:
- 46
- Uploads:
- 56
- Thanks:
- 200
- Thanked:
- 633 times in 576 posts
September 18, 2011 at 11:31 am #168683Most of the time when we build a Joomla site we need to add some code to the <head> or <body> so I am going to show you a way that you can make those modifications on JA T3 plugin without editing the T3 plugin which is the same when you hack Joomla Core files and when you upgrade you will have to redo any changes you have done before.
So in this case we are going to build our T3 overwrite folder!
To do this you have to create a new folder under </templates/<Ja-template>/page/ (you can see what I mean on the image attached:
So now that we have created our new folder we have to copy the default.php file from T3 plugin folder to this new folder! You can find this file here: /plugins/system/jat3/base-themes/default/page/default.php
- Now that we have done this copy paste staff we can proceed with editing our default.php.
- I prefer to use Notepad++ to edit my files but you can also use any text editor you like ( I don’t recommend windows notepad for several reasons)
For a start I am going to import Google Analytics code, there is a really good reason to import Google code on default.php since default.php is called on every single page on your website and it’s better than using a plugin since you won’t increase page load time as every plugin has to find the proper place to inject Google Analytics code on every page load on the fly.
Google suggests that we add the code just before the closing </head> tag ( this is solution no1 ) so on our favorite text editor we open default.php (the instance we have copied under our template folder) and we add GA Code:
<head>
<?php //gen head base on theme info
$this->showBlock ('head');
.
. <!-- Normal default.php code is here --?>
.<?php echo $this->showBlock ('css') ?>
<!-- Our Google Analytics Code -->
<script type="text/javascript">var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-XX']); // Replace UA-XXXXXXX-XX with your own GA Code
_gaq.push(['_trackPageview']);(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();</script>
</head>
Of cource an other solution is to create a new file called for example – > analyticstracking.php and place this file on the same folder ( aka /templates/ja-template/page/ ) and then instead of adding the code that I show you before you can just add a call to this file.
In this case Google suggests that we add this line:
<?php include_once("analyticstracking.php") ?>
Right after the <body> opening tag which can be found on default.php file and in line around 31. So our default.php file should look like this :
<body id="bd" class="<?php if (!T3Common::mobile_device_detect()):?>bd<?php endif;?> <?php echo $this->getBodyClass();?>">
<?php /* Google Analytics Code call */ ?>
<?php include_once("analyticstracking.php") ?><div id="ja-wrapper">
.
.
.So this is the way you can edit T3 plugin and still be able to upgrade without loosing any job done. And also you can add any other code needed, like a chat module at the bottom of your page ( adding the proper lines of code before the </body> closing tag etc according to the software you are going to use).
- December 21, 2011 at 7:34 pm #430730
Thank you I am in the process of a complete redesign and I was leaving the google anaylrics to last as well as Alexa and a few others that need to go into the head. I may get in touch with you about a few other questions
Thanks!AuthorPostsViewing 2 posts - 1 through 2 (of 2 total)This topic contains 2 replies, has 2 voices, and was last updated by livingwellmagazine 13 years ago.
We moved to new unified forum. Please post all new support queries in our New Forum
Jump to forum