7 Easy Steps to Create a WordPress Plugin

Making a very simple plugin and getting it recognised

Headers are important

Plugin content

write a function to initialise the plugin, this is called later to write some content onto the specific plugin configuration page (under “Options”, where you see all the other plugin config pages). All this function does at the moment is return some HTML as a token gesture to show that we’ve actually got something working. The “wrap” div is significant because that is a WordPress wide constant, placing all your content into a suitably styled container.

  1. function initDemoPlugin()
  2. {
  3. ?>
  4. <div class=“wrap”>
  5. <h2>Seopher.com demonstration plugin</h2>
  6. This is just some sample content to show that we’ve got control over the content of this page.  Rawr!
  7. </div>
  8. <?php
  9. }

Add the plugin to the submenu

This step involves writing a function to add the plugin into the “Options” sub-menu so that when it is activated you have somewhere to visit to configure the settings. See the code below:

  1. function addPluginToSubmenu()
  2. {
  3. add_submenu_page(‘options-general.php’, ‘Seopher demo plugin page’, ‘Seopher demo plugin’, 10, __FILE__, ‘initDemoPlugin’);
  4. }
  5. add_action(‘admin_menu’, ‘addPluginToSubmenu’);

All we’re doing is tying into the “add_submenu_page” function, where we’re passing several parameters. Firstly we’re specifying the parent page (in this case options-general.php) that the sub-menu page will sit under. The second parameter is the page title for the new page (as seen in the browser’s title bar). The third param is what appears in the sub-menu navigation. The next parameter is the priority of this function which can just be left at 10 for now. The final param is the function that is called to populate the page, in this case it’s the function we created in step #2.

Finally we use the WordPress function “add_action” to call the function we’ve just written, simple!

Upload the PHP file

So if you compile all the code we’ve shown so far (or download my version here) into a PHP file, you can then upload it to the WordPress install. Upload the PHP file to “/wp-content/plugins/” and you’re done.

Activate the plugin!

Log into your WordPress install and visit the “Plugins” tab, And Activate it.

Visit the config
Click “Options” and you should see our plugin added to the sub-menu

Clicking on that takes you to our plugin configuration page. All this page does is output the return of our initDemoPlugin() function that we wrote in #2. So clicking on “Seopher demo plugin” takes us to this page