Browsing all articles tagged with wordpress
Dec
17

How to create a Wordpress plugin

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 :)

Dec
10

Installing Smiletag Shoutbox in Wordpress

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!

Connect with me


What I'm Doing (via twitter)...

  • is applying for US visa. The website is not helping at all http://twitpic.com/16hvxp 5 days ago
  • @abumuaaz want to focus on my wireless project (yes, I get paid for that) and some development work. Ada job to pass ka? :) in reply to abumuaaz 1 week ago
  • is running 'sudo dd if=/dev/zero of=/dev/sda' on his laptop. Will it work, my computer forensic friends? 1 week ago
  • is on his first day of being jobless, hahaha. 1 week ago
  • finished reading Crowdsourcing: Why the Power of the Crowd Is Driving the Future of Business, in 32 hours. Next, Wikinomics. 1 week ago
  • is on his way to island hopping. Woohoo! 1 week ago
  • is leaving on a jetplane, don't know when he'll be back again... 1 week ago
  • missed his flight to KK. Will need to take the first flight tomorrow and pray he'll make it for his 9am meeting. 1 week ago
  • More updates...

Categories

Tags

bash blog book database debian embedded gutsy howto hsdpa html kde kubuntu linux lpi nature network Photoblog photography php pylons python recovery script security shell sqlalchemy ssh ubuntu vim wireless wordpress

Blogroll

Flickr Photostream
DSC 0336Do not pluck the tea leaves... Yeah, right.I am Super Faiq, and I have a D3!But we don't have much time to cover the whole area.The truth behind your cup of tea, muahahaha....It's my thing. I can do it eyes closed.We wander around the tea plantationTrying out Teletubbies modelingWe get bored easily, and within minutes we're already at a tea plantation.