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










