Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

User:Annapootle/Your First Plugin

Your First Plugin

Creating your first plugin for WordPress can seem like a lot of work. If you start out right, it will be easy and soon you can be a pro plugin developer! In this tutorial we will be making a simple plugin based off of the Hello Dolly plugin for WordPress, that displays animal names. This isn't per se something you would do, but the code is simple.

Naming Your Plugin

Name your plugin. Search Google and the WordPress Plugin Repository before choosing the name. If you make a plugin that emails a contact list, use 'email' in the title. We will call it

Header Text

First, open a text editor. Notepad will work. Insert this text into the document:

<?php /* Plugin Name: My Plugin Plugin URI: http://pluginsite.com/ Description: Short description. Version: 1.0 Author: Author URI: http://mysite.com/ License: GPL2

  • /

?>

Then this text:

<?php /* Copyright 2011 Your Name (email : somebody@example.com)

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2, as 
   published by the Free Software Foundation.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  • /

?>

This is the header and the license. The header is used to identify your plugin when someone downloads it.

The PHP File

The base file you will need for your plugin to run is a PHP file. Based on your plugin name, create the PHP file name. In a plugin called 'My Favorite Posts' your PHP file might be
myfavposts.php
.