Skip to content

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

  1. 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.
  2. In wp-content, open the plugins folder.
  3. Create a new folder inside of your plugins folder. Name it something like myplugin.
  4. In that folder, create a file. The convention is to match your folder name with a .php at the end. This isn’t required though. But to fit that example, create a file called myplugin.php.
  5. 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.
  6. 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.
  7. 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:

Writing a WordPress Plugin From Scratch: A Step-by-Step Tutorial

 

Yay! 🎉 You made it to the end of the article!
David Hayes
Share:

0 Comments
Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!