How To Create A WordPress Plugin In 10 Minutes

There are plenty of similar posts available all over the internet so I’ll try to keep this short and to the point.

Local Developer Environment

To create a WordPress plugin, first you’ll want to setup a WP developer environment. There are many options but I recommend using VVV (Varying Vagrant Vagrants).

The installation is quite simple. First install VirtualBox and then clone the VVV repository in your local machine; let’s say to a folder called vagrant-local. Then cd into it and type in vagrant up.

The three commands I mentioned are listed below:

git clone -b stable git://github.com/Varying-Vagrant-Vagrants/VVV.git ~/vagrant-local

cd ~/vagrant-local

vagrant up

It will take a while to execute if you’re running it for the first time. It could fail because of network issues. If it does, just try again with vagrant up.

Once it finishes executing, you shall be able to load the two (default) local test sites at one.wordpress.test and two.wordpress.test in your web browser.

Create your first WordPress plugin

Now that you have a local WordPress development environment ready, you can start creating your very first WordPress plugin.

Open the plugins folder in one of the two test sites. For the first test site, it should be located at the following path:

vagrant-local/www/wordpress-one/public_html/wp-content/plugins

Create a new folder inside it. Let’s call it Mars for no reason at all (or you could just name it whatever you like).

Now create a file called mars.php inside this new folder. We need the file-name to match the folder-name.

Paste the following content inside it:

<?php
/**
* Plugin Name: Mars
* Plugin URI: https://www.yourwebsiteurl.com/
* Description: I'm your first plugin. I'm also the 4th planet from the Sun in our solar system.
* Version: 1.0
* Author: Your Name Here
* Author URI: http://yourwebsiteurl.com/
**/

Save the file.

Activate the plugin

Open the wp-admin dashboard in one.wordpress.test site > go to plugins and you shall see your first plugin in an inactive state:

Activating it does nothing at the moment but it should help you understand the code above.

That’s all for now. Let’s make it do something in the next post.

Leave a Reply

Your email address will not be published. Required fields are marked *