Posts Tagged ‘wordpress’

How to create a WordPress plugin

Written on December 17th, 2007 by shakir
Categories: Information Insemination

I’m into writing a plugin for WordPress, and so let me just share here how easy it is to actually create one.

For an example, we’re going to write a plugin that will insert a Google Adsense to our blog post.

From our WordPress installation directory, create a file named google_adds.php in the wp-contents/plugins/ directory and add these lines; 

<?php
/*
Plugin Name: Google Adsense
Version: 0.1
Plugin URI: www.mohdshakir.net
Description: This plugin will display Google Adsense in every post
Author: Mohd Shakir bin Zakaria
Author URI: www.mohdshakir.net
*/
?>

To see what it does, login to your WordPress admin panel and go to the Plugins section.

As what can be seen from the screenshot, the information of the plugins there were taken from the comments on our plugin code. We can now activate the plugin, but for now our plugin doesn’t really do anything useful.

Let’s go back to our PHP code, and add some lines to be as the following

<?php
/*
Plugin Name: Google Adsense
Version: 0.1
Plugin URI: http://www.mohdshakir.net
Description: This plugin will display Google Adsense in every post
Author: Mohd Shakir bin Zakaria
Author URI: http://www.mohdshakir.net
*/

function adsense($text){

        $adsense_code = <<<EOT
# Add your own Adsense code here
EOT;

        return $adsense_code . "<br \>"  .$text;
}

/*
  Add filter is a built in WordPress function, and the_content
  is a WordPress variable of a single post content.
*/
add_filter('the_content', 'adsense');

?>

Let’s see if it works

That’s it, our first fully functioning Google Adsense plugin :)

Installing Smiletag Shoutbox in WordPress

Written on December 10th, 2007 by shakir
Categories: Information Insemination

Smiletag Shoutbox is the shoutbox that I have on my website’s sidebar. I’ve been using it since I was using Joomla for my website, and now that I moved to WordPress, Smiletag is still my shoutbox of choice.

Installing it in Joomla is very straightforward, while it’s not really the case with WordPress, as it requires a little bit of coding.

The application can be downloaded from Hivemind’s website (requires free registration)  and it can then be installed as any other WordPress plugin. The shoutbox however doesn’t immediately show up in the page, and there’s no option in the admin console for that.

To add it to the page we must add some codes, and in our case, to the sidebar’s code. Edit it from the admin panel;

Presentation -> Theme Editor -> sidebar.php

or can be edited with any editor;

/path/to/current/template/sidebar.php

This is an example of a very simple WordPress template with widget support;


The sidebar uses <ul> for its items, and so we need to add <li> element to add our shoutbox (and probably any other static stuff) to it. We also need to add a header (<h2> probably) for the item’s title, and add the shoutbox’s code to it. The final sidebar should look something like this;


This might not exactly be the case with every template, but the idea is about the same. Happy blogging!