I’ve been using WordPress since 2007. I’ve often tweaked themes to achieve basic changes in functionality. Sometimes that’s not the right approach because you’ll lose that functionality when you switch to another theme. A better approach is to put this functionality into a plugin. I first started by hand-crafting plugins from scratch by following the plugin API documentation in the WordPress Codex. That can be a little complicated if you’re new to WordPress development.
A better way is to start with a plugin template. One such template is the Pressography WordPress plugin template. The advantages of using this plugin template are:
- you’ll have examples of working with the WordPress API functions
- the template is written in an object-oriented fashion, which is a sensible way to structure your plugin’s functionality
- the plugin template includes sample code for setting up plugin option pages and working with the WordPress widget API
- the template includes some find and replace tokens to quickly customise the template for your needs, these are:
- {Full Plugin Name}
- {plugin_slug} and
- {widget_slug}
The steps to get started are:
- Create a directory in wp-content/plugins for you new plugin.
- Create the plugin’s main file (a .php file) based on the template code.
- Search for and replace the 3 tokens above with the name and slugs see note you define.
WordPress ships with some default plugins. These are examples to refer to for use of the WordPress APIs.
I also recommend that you refer to the following resources:
- Writing a Plugin
- Plugin API
- Other resources identifed on the WordPress codex site.
Once you’ve finished your plugin, you might think that it has wider appeal so consider distributing it via the WordPress plugin repository.
NB: the term slug is a more generic term that doesn’t only apply to post and page URLs. It can also be used for other facets of wordpress, including categories, tags, widgets and plugins to name a few.
No related posts.