Making a Plugin Inside the Dashboard
Have you ever found a code snippet in a forum that said “Just put this in your
functions.php file”? Don’t do that. In this video, you’ll learn how to do this by creating a plugin from within your WordPress dashboard – it’s easier and safer than dropping code into your
This workshop will show you how to do this using a plugin called Pluginception – while Learn WordPress always strives to present multiple options for products to use, there are no known alternatives to Pluginception at the time of publishing this workshop.
- How to create a plugin inside your WordPress dashboard using Pluginception.
- Understanding the minimum requirements for what makes a plugin.
- How to add code to a website in a plugin.
- Should you edit an active plugin?
- Should you put code snippets into your
Hey folks, welcome to another HeroPress Tip of the Week. This week, I’m going to show you how to quickly and easily make a plugin. Even if you have no idea how to do that.
We’re going to start by going to the plugins page in WordPress, we’ll go to Add New. And we’re going to install a plugin called “Pluginception” which is a plugin for making plugins. So we’ll install it right now – many thanks to Otto for this plugin, because it’s great. And activate. So let’s activated right there.
And now over on the left, we have a new menu item called “Create a New Plugin”. Let’s click that. And the only really required element on this form is the plugin name, you can see all the others are optional, you want to make it unique, something that no one else in the world is going to come up with. So this could easily be something with your name in it or whatever. So I’m going to call it “Topher’s Custom Plugin”. Now the slug you need that slug needs to be unique also, but it will make a new one off the name. So you can leave it blank if you want. And I recommend doing that.
I like to put in a description and a version – 1.0. The author, you can do a WordPress.org handle like that. And you can put in your own web address, license, whatever you want. But again, the only required bit is the plugin name.
So I’m going to create a blank plugin and activate it.
And now we’re in the plugin editor, which did not come with this plug in that’s built into WordPress. And there’s a thing here that says “Be careful, you can break things.” So you need to say I understand. But at this point, we have a plugin, we’re done. It doesn’t do anything. But this is all a plugin. It’s one file name. In this case, it’s in a folder. And there are some headers here. And that’s it.
So I’m gonna click “Update File” real quick. You’ll see this file edited successfully. And if I go back to installed plugins, you’ll see it right there.
Now, if you’re going to edit this plugin, I recommend deactivating it because when you if you break something, and then try to activate it, WordPress won’t let you – it won’t let you break your site.
So let’s go back to the plugin editor. And over on the right here, I’m going to choose Topher’s Custom Plugin choose “Select”. Here it is. And the reason you would want to do this is if you see in a forum or something, a little bit of code that does something you want. And they say put this in your functions.php file, you don’t want to do that you don’t that ties it to your theme, you don’t want to do that you want to put it in a plugin.
So I’m just going to put in a little code here…function()…we’ll call it tophers_header_comment. There now I have a function and I want to print an HTML comment. So it looks like this. “This site was built by Topher.” And a little semicolon there at the end. And I want this in the header of my site. So I’m going to put in add_action WP underscore head then in quotes, the name of my function…there, that’s all there is to it!
And this is exactly the kind of thing you might find in a forum somewhere that says just put this in your functions file. So I’m going to hit “Update file” in then come back to my plugins and activate. There we go.
Let’s go to my homepage in view source. And I’m going to search for Topher and you’ll see it right here. “This site was built by Topher.”
Now I want to show you what would happen if I broke it somehow. So I’m going to deactivate go to my plugin editor. Choose my plugin. And I want to take that semicolon off right there. “Update File” – it let me do it. But if I activate, it says “no could not be activated.” And so it is not activated. So I had bad code that broke something, but it didn’t break my site, front of my site looks just fine. Everything’s cool. So this is great.
And it also tells you, there’s an unexpected curly brace on line 15. Here’s a pro tip about PHP. The error is almost always on the line before it mentions. So we’re going to edit…so it said, it was on line 15 unexpected curly brace, but the problem is here on 14 because there’s no semicolon.
There we are. Back, activate, and all as well.
So if you’re ever trolling for some code that does something you want and the instruction say put it in a functions.php file. Don’t do that. Make yourself a little custom plugin, just like this one, and paste it in there, just as if it were a functions file. And it should work. And if it doesn’t, it doesn’t melt your site.
I hope you find this useful!