Getting Started with WordPress Plugin Development

2014-06-29

Mark Tsibulski

Getting Started with WordPress Plugin Development

Beginner guide to creating your first WordPress plugin with automatic image injection for posts.

Writing plugins for Wordpress may seem like a daunting task if you’re new to Wordpress. But all it takes is a good starting point to get the ball rolling. Today I’ll show you how to get started with your first simple Wordpress plugin. For this example, we will be making a plugin that automatically adds an image to all new posts.

First, you will need to make the appropriate directories and files. In your/wp-content/plugins/directory, make a new folder with your desired plugin name, and a .php file with the same name.

You should have a structure similar to this:/wp-content/plugins/auto-image/auto-image.phpmaking sure that whatever name you chose, you use it for both the file and directory.

Open up the .php with your favorite editor and add some basic plugin info into the file header:

'; } ``` Hopefully your function name doesn't conflict with existing functions, so give it a somewhat unique name. Finally, addadd_filter('the_content','auto_add_image', 1);between the plugin info and the function start. This will call a Wordpress functionadd_filterwhere the first value passed is the hook name "the_content" and the second being your function name "auto_add_image". You should have something similar to this: ```php

'; } ``` Now when you replace the placement text with your image URL, all you have left is to save and then enable the plugin under Wordpress Plugins settings. Obviously this is a very primitive plugin, but it shows how simple it is to get started with Wordpress Plugins. Make sure to read up on[http://developer.wordpress.org/](http://developer.wordpress.org/)and the[Wordpress Codex](http://codex.wordpress.org/Writing_a_Plugin)for more documentation on Wordpress and writing plugins for it.