Add Statcounter code to certain page?
-
Hi everybody,
I want to add the Stacounter code to a certain page. Is that possible? I asked the Stacounter team, but they don’t seem to know.Johanna
-
Firstly you need to do these changes in a child theme, otherwise they will not survive an update. Details here:
creating a child theme http://codex.ww.wp.xz.cn/Child_ThemesNow because of your special usage you cannot use the Statcounter plugin, you have to use the regular HTML code instead.
Copy the file “footer.php” from your parent theme to your child theme directory.
Code an if block that only outputs the statcounter code under specific conditions.EDIT: I just had a DUH! moment. The easiest thing to do is to assign a custom page template to the relevant page(s). The statcounter HTML code goes in there.
Hi Ross,
Thanks for your answer.
I understand what you are saying, but I have problems how to do this.
If I use the footer.php in the child theme, what exact code do I have to include for the Statcounter code?
And if I use the second option, to use a custom page template, what code do I use in that? I found the template page, but it says at the bottom to get the footer. I assume I have to change that. But how do I do that?
Unfortunately I am not good in php.Johanna
The code you will put into your custom page template is like:
<script type=”text/javascript”>
var sc_project=xxx;
var sc_invisible=1;
var sc_partition=54;
var sc_click_stat=1;
var sc_security=”yyy”;
</script>
<script type=”text/javascript” src=”http://www.statcounter.com/counter/counter.js”></script>
<noscript>
<div class=”statcounter”>
<img class=”statcounter” src=”http://c.statcounter.com/xxx/0/yyy/1/” alt=”wordpress stats plugin” /></div>
</noscript>Copy/paste your own code that has your project and security settings.
but it says at the bottom to get the footer.
No, leave it in place, put the above code just before it. Put it into an HTML context
(outside <?php ... ?> )Unfortunately I am not good in php.
My respons is to say “yet”. The ability to actually write PHP is a lot different to being able to manipulate it.
Hi Ross,
Thanks for that.
But I am confused about htis part:
No, leave it in place, put the above code just before it. Put it into an HTML context (outside <?php ... ?> )
Is it possible to write down the entire code here?As for php, I am pretty good with design, but php is so difficult for me.
Johanna
The entire block of code depends upon just how your theme is arranged, but It will be like this:
?> <script type="text/javascript"> var sc_project=xxx; var sc_invisible=1; var sc_partition=54; var sc_click_stat=1; var sc_security="yyy"; </script> <script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script> <noscript> <div class="statcounter"> <img class="statcounter" src="http://c.statcounter.com/xxx/0/yyy/1/" alt="wordpress stats plugin" /> </div> </noscript> <?php // calling footer.php get_footer();We should create a partnership, my designs suck, but php is pretty routine.
Hi Ross,
Ok I will try it out this week. Thanks!
As for partnership, I don’t know if you are on Facebook, but we could talk there. My profile is: https://www.facebook.com/ouwerlingJohanna
Hi Ross,
Thanks. This works!
But the Statcounter team found another more simple solution.
Just copy the basic statcounter code for your newly created project and go to the page that you want to track. Go to text mode and paste your code at the bottom of the page. And update the page. That is all.
It works great!Johanna
The topic ‘Add Statcounter code to certain page?’ is closed to new replies.