My First WordPress Plugin

I wrote my first plugin for WordPress a couple of days ago, it was a very simple plugin. All I wanted to do was to insert a few lines of javascript - Google Analytics javascript - to the bottom of each page here.

Since GIDBlog.com is a blog hosting site, and there are always multiple themes, or WordPress templates, to choose from, adding (pasting) lines of javascript directly into the theme files seemed like an insane idea.

I don’t know much about WordPress and I am still figuring things out, but this is what I did to get the Google Analytics code to show on every page.

Here is a copy of the plugin script.

Unlike regular WordPress plugins though, this one needs to be inside the wp-content/mu-plugins/ folder.

I would like to thank cableguy, once again, for all the pointers! :)

 
4 Comments »

Hmm, still having problems with this. How do I actually add the code? When I try to access the /mu-plugins folder, I get a “404 Not Found” error. I’ve looked around the Admin section but I can’t find anything for true site management.

Comment by crystalattice — May 15, 2007 @ 5:25 am

Right now, everybody’s site is tracked by one piece of Analytics code. If you’ve registered your account here with a gmail address, chances are high that you can login to Google Analytics and view all (ALL) the stats for this site already.

In the future, I will add an option for blog owners to paste their own Analytics code to their respective blog(s), though I am not sure how to do this yet.

Comment by J de Silva — May 15, 2007 @ 8:51 am

Is this the same thing for Google AdSense? I mean, individual sites can’t add or customize ads? I haven’t seen a way to put them in, unless it’s as a sidebar widget.

Comment by crystalattice — May 16, 2007 @ 1:18 am

Yes, this is also in the TODO list.

At the moment, the main ads (2 x AdSense for content, and 1 x AdSense AdLink ad unit) appear automatically on each page. I am still adding them to the themes, e.g. I haven’t inserted all the codes for the theme that you are using right now. I will rush to do this tonight.

Comment by J de Silva — May 16, 2007 @ 1:27 am

Leave a comment

Theme designed by J de Silva exclusively for GIDBlog.com.