Creating a Simple WordPress Plugin, Under the Hood
WordPress plugins are where a developer who’s first branching out from themes is likely to go. The speed bump someone like that is likely to hit is simply making a plugin: where do I put what? What do I need? What makes a plugin activate-able?
In this Quick Guide we cover exactly that stuff. What do you need to make WordPress recognize it, and what should a plugin do. The short answer: not what we did in this video. :p
This plugin is (kind of intentionally) silly and useless. Because our focus in the Quick Guide is simple making a first WordPress plugin that does anything at all. Including taking down your WordPress site. SO: DO NOT SLAVISHLY FOLLOW THIS TUTORIAL ON A LIVE SITE YOU AREN’T READY TO WHITESCREEN.
That warning out of the way, here’s the video that explains what we’ve done in the Quick Guide, and what it tells us about WordPress plugins themselves.
Making Your First WordPress Plugin: Breaking Your Site
- In a file browser — your local operating system one if you’re using WAMP or MAMP, an (S)FTP client if you’re working on a remote server — open up your content directory. It’s usually
wp-content, open the
- Create a new folder inside of your
pluginsfolder. Name it something like
- In that folder, create a file. The convention is to match your folder name with a
.phpat the end. This isn’t required though. But to fit that example, create a file called
- In that folder, place in the plugin comment header. Modify it to match your desires. (That is, keep the things to the left of the colons (:), but change the things to the right to whatever you want them to be.
- Go into your WordPress admin area. On the page Plugins > Installed Plugins, you should now see the plugin you named in step 5. Activate your plugin.
- IF YOU WANT TO BREAK YOUR SITE, add a line of PHP to your file, like
die('my plugin was here');. If you don’t want to break it, write some valid and non-breaking PHP instead. (That’s a big task, but we have to draw the line somewhere in this tutorial.) The code from the previous Quick Guide — about using WP_Query in a shortcode — is a good example.
Here’s all the code from this tutorial in one block. A final warning: this code is intentionally capable of making your WordPress site break.
die is not a joke.
<?php /* Plugin Name: Quick Guide Plugin URI: https://wpshout.com/quick-guides/ Description: For Quick Guides Version: 0.1.0 Author: WPShout Author URI: https://wpshout.com/ */ die('my plugin was here');
For a more in-depth WordPress plugin creation example, see our full-length article: