There is two words to describe wordpress: “Simplicity” and “Flexibility”. You can do almost whatever you want with this application and its tons of free themes and plugins. This is a simple plugin example that include the steps I used to write my first plugin.
In this case I will replace the phrase “happy_face” inside the post by an image.
The Standards.
The Name
If you want to share your plugin with the community it has to be unique. No other plugin on the WordPress Plugin Directory can share this name.
In this example let’s use:
Happy Face Replacer
The Files
You need at least one “main file” .php with your principal functions. The name of this file could be derived from your plugin name. Besides you can use the others necessaries folders and .php, .js, .css files.
Our main file could be:
happy_face_replacer.php
The Header
At the top of your main file you need to include this header.
<?php /* Plugin Name: Happy Face Replacer Plugin URI: http://www.pluginURI.com Description: Plugin Description Here. Version: 1.0 Author: Your Name Author URI: http://www.yoursite.com */ ?>
It will make your plugin look like this at the plugins panel:
The Hooks.
Beftore the version 1.2 to change the functionality of WordPress modifications (hacks) of the source code was needed. Now you can interact with the core of the application using the hooks.
The hooks intercepts the default wordpress behavior. For example, before wordpress shows the content of a post it check if there is a function (hook) registered that modified “the content”, if so the content is passed to this function before to print the final result.
There is two principal hooks:
Actions related to specific events like: add_category, get_header, get_footer.
To use the hook action you need to use this function:
add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
On this link Plugin API/Action Reference you can find the ‘hook_name’ that you need to intercept.
The ‘priority’ is optional and specifies the order in which the functions associated with a particular action are executed (default: 10).
The last parameter defines how many arguments your function can accept (accepted_args = 1 by default).
Filters are function to modified the wordpress data like: the_excerpt, the_title, category_description. Visit Plugin API/Filter Reference.
If you want to ‘hook’ a function to a specific filter action you need this similar function.
add_filter ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
In my example I will use a filter hook. So the main file could be something like this:
<?
add_filter('the_content', 'happy_face_replacer');
function happy_face_replacer ($content) {
$happy_face_image = "<img src='happy face image URL'>";
return preg_replace('/happy_face/', $happy_face_image, $content);
}
?>
The function “happy_face_replacer” takes the content of your post ($content) before to be printed and replace the phase “happy_face” by the image.
That’s it.
If you want to try this simple plugin just download the file and install it: ![]()
Here you have some useful links:
Writing a Plugin
Plugin API/Hooks 2.0.x
Plugin Resources
Custom Queries

July 25, 2010 at 1:40 pm
http://www.superdirectorysubmitter.com/
finally the perfect solution pour webmasters:
super directory submitter Website Submitter
is a program designed to submit your web page to thousands 20 000
of higher Quality directories. It will save you a lot of time, effort and money since its fully semi-automated. You just enter some information about your web page and the program does the rest. With SDS software you will never need to search for places to advertise again.
January 29, 2010 at 9:00 pm
This sort of worked for me. I kept getting “couldn’t modify header” errors. I was able to adapt this and add it to my functions.php so it was a permanent fixture of my theme though.
March 4, 2009 at 12:48 pm
@Jim Spaulding
Yes…Html is the basic markup language for Web pages. Javascrip and some frameworks like jquery could help you a lot.
Thanks,
Alain
March 4, 2009 at 7:30 am
Thank you for this well written tutorial. I have been wanting to learn more about PHP and this gives me a nice start. You have whetted my thirst for knowledge here. Now I want to learn the language even more. I suppose I’d better learn HTML first though eh?:)
February 7, 2009 at 4:07 pm
Year. It’s great, if you are a good programmer, but if a user…
November 9, 2008 at 3:46 am
Sounds good. Will definitely give it a try. Thanks for sharing, buddy.