DeutschEnglish

Submenu

 - - - By CrazyStat - - -

26. April 2012

How to include CrazyStat in WordPress

Filed under: CrazyStat,PHP,Wordpress — Tags: , , , , , — Christopher Kramer @ 00:52

Of course it is possible to include CrazyStat in wordpress. I will describe here how it can be done. This approach assumes you have your own wordpress installation and can edit templates. It might not work this way if your blog is hosted on wordpress.com or similar. But I guess using CrazyStat in these cases would still be possible. Contact me if you need to know how and I will have a closer look.

So I assume you have a running wordpress installation and installed CrazyStat like described in the readme (at least steps 1-6 of quick install instructions). I assume you have a backup of your wordpress installation (at least the themes folder).

So the question is where to put the include code:

<?php @include_once("stat/src/include.php"); ?>

Log into the wordpress admin panel and click appearance/editor (German: Design/Editor). Make sure you selected the correct theme in the dropdown menu on the top right.

In case you do not want to use a counter

Click on “footer.php” on the right. You will see some HTML / PHP code in the editor. Put your cursor just before </body> (which should be quite at the end).  This is the best place to insert the CrazyStat code:

<?php @include_once("stat/src/include.php"); ?>

The path is seen from the wordpress root-directory. This code assumes you installed CrazyStat in the wordpress root-directory under “stat”. In case you installed it one level higher, you would need to use:

<?php @include_once("../stat/src/include.php"); ?>

Save your changes.

You might also need to adjust $config_rel_path. See config-documentation for details.

In case you want to use a counter

In this case, you’d need to find the place in your template where you want to place the counter. This should normally be somewhere after <body> in header.php, before </body> in footer.php or in sidebar.php. Unfortunately you need some HTML experience to find the correct place here. Use the same code as above.

In case you have problems

Please ask in the CrazyStat support forum in case you have problems or questions (no registration required at the moment!).

I hope I could clarify this for some people. Maybe I will do a wordpress plugin sometime. If you think this would be a great idea, tell me in the comments.

Alternative option: Use the WordPress plugin mzz-include-CrazyStat (Update 2017-02-17)

The problems with the solution described above are:

  • Whenever the theme is updated, the change of the footer.php might get lost.
  • If you switch to another theme, you need to add the CrazyStat code again.

To solve these problems, CrazyStat user Morgan Jassen developed a small helper plugin that just inserts the include code:

Find it here: https://github.com/mjassen/mzz-include-crazystat

I just found this today and have not tried it yet, but think it is the better option. Thanks, Morgan!

Recommendation

Try my Open Source PHP visitor analytics script CrazyStat.