Skip to Navigation

How to Create a Simple WordPress Plugin

Printer-friendly version

Creating a plugin in WordPress is easier than you might think. There are currently over 8,500 plugins in the wordpress.org repository (not including paid plugins), so that should say something.

For starters, WordPress has a fairly extensive plugin API system, granting you the ability to hook into various parts of WordPress without needing to touch the core code directly.

WordPress comes with two kinds of hooks: actions and filters. Actions allow you to run PHP functions at a certain point of execution (such as when the header has loaded or when a post has been submitted). Filters also allow you to run PHP functions — modifying data passing through them — before either being outputted or saved to the database.

In the following example, I've created a simple plugin to email a specified user whenever a new post has been published: 

<?php
/*
Plugin Name: Just Published!
Plugin URI: http://forumone.com/
Description: Notify a user once a post has been published.
Author: Matt Gibbs
Version: 1.0.0
Author URI: http://forumone.com/
*/

function jp_email_user() {
    mail('some@email.com', 'A new post has been published!', 'Some content');
}

add_action('publish_post', 'jp_email_user');
?>

Within the top comment area, WordPress expects some information about your plugin, such as the plugin name and version. There's a single action hook that runs the function "jp_email_user" right whenever a post gets published. Combine this file with a readme.txt file and you are all done. This is about as simple as it gets.

Hooks are great because they allow you to change how WordPress works without needing to touch any core code. Much of the WordPress code can be "hooked" into, allowing for an extremely high level of flexibility, comparable to Drupal. Best of all, since there are so many plugins already in the repository, there is likely one that already does what you need. If not, there are thousands of working examples to guide you towards creating your very own plugin :)

Comments

I agree.

Thanks for the useful WordPress suggestions and information. It is a real timesaver for me.

In view of large number of

In view of large number of wordpress plugins available, it is easy and simple to create wordpress plugin. Thanks for sharing the interesting plugin herein. Nice job. product and development

Really simple

I am quite agree with your view presented in this article about WordPress. Certainly there is a good number of debate and hot discussion over the comparision between various aspect of application of Drupal & WordPress but my opinion is with WordPress for it's simple application and as you say higher flexibility. obr?czki ?lubne

I love the color-coded health

I love the color-coded health outcome maps as this reveals the health standards of each state in a true visual manner.
Online Shopping

I really agree with you guys

I really agree with you guys here even though I too was in the group who thought creating simple wordpress plug-ins were arduous. I am not saying it is not that taxing as one might expect to be so. It is hard! But Wordpress have changed all that assumptions for good and it is now very convenient for all of us to get inside several parts and that too without touching the core code directly! That seems to be a great improvement and I hope this keeps up despite the advancements of plug-ins! Stereolithography

appreciation

That's a very useful tip and valuable information. You saved me so much time and countless efforts. On by behalf I'd like to share this tutorial http://www.pdfok.com/watch/WP-Blog-Guru.pdf-14608545.html to (as mentioned here) discover all the latest tips and tricks to turn your standard Wordpress installation into a traffic magnet…….almost instantly!:)

plugin works perfectly.

plugin works perfectly. thanks for the comment.. ilan ver

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.