Demystifying the WordPress Plugin

I asked one of the guys on my team to build a WordPress plugin, he balked. I realized that he just didn’t get how easy it is. So I thought I’d dedicate some time to dispelling the myth that plugins are complicated to write. “Plugin” sounds formidable. But really, a plugin is a file in the plugins directory with a comment. That’s it. To build your first plugin create a file, name it whatever you like, and place the following code at the top:

<?php
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/

Upload that file to YOUR-SITE-ROOT/wp-content/plugins/ and voilà!

Go to your plugins menu and you’ll see your shiny new plugin there.

What do you put in there besides the comment? Typically, anything you’d put in your theme’s functions.php file. Unlike with the functions.php file which runs everything you put in it, where plugins are concerned you can decide whether to “activate” the code or not.

Here’s a great post with 25+ potential plugins. Let’s try #3 (Don’t forget to change the plugin’s name):

<?php
/**
* Plugin Name: Remove WordPress Version Number
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/

function wpbeginner_remove_version() {
    return "";
}
add_filter("the_generator", "wpbeginner_remove_version"); 

See! Wasn't that easy?

Typically, you'll want to add to your functions.php file code that is necessary for your theme to run, and make plugins for all functionality that is separate from the theme.

There's a lot more to say about plugins, the example above is rather simple, but it should get you on your way.