When you change themes, your customizations stored in there will get lost. So that’s where a custom functionality plugin comes into play. You can place your changes there and they will stay there even if you change themes. So let’s go over how you can create a custom functionality plugin today (and you don’t need to be a developer to do so).
Hey there and welcome back!
If you have a WordPress website, you’ve probably figured out a way to customize it. And it probably involves PHP because you want to do more than just change the colors or style, but you really want to change the functionality.
Yes, even if you’re not a developer, you’ve probably gone out to find a tutorial about how to add a custom post type, add a custom taxonomy and even change the style of your login screen.
And those tutorials probably tell you to add some sort of code into your theme’s functions.php file. And that’s great. It’s an easy file to locate and to edit, and you know that code is going to run because that file is always loaded with your theme.
But what happens if you change your theme? You’re going to lose all of those changes because that functions.php file will no longer be run, and your new theme’s functions.php file will be run.
Now of course you can migrate all of your changes over to the new functions.php file, but isn’t there a better way to do this?
In fact there is. And we do it through a custom functionality plugin.
This is a plugin that basically acts like a functions.php file in your theme except that it always runs no matter what theme is active on your website. And the best part is that you don’t really have to be a developer to build one. Here I’ll show you.
Okay, so here we are inside of a theme that I have. And I originally had some styling to go along with this form, but lost it when I changed my theme because I had it in the functions.php file. So today we’re going to correct that.
And before we begin I do what to mention that I have a starter functionality plugin in a GitHub repo that’s linked to below in the description where you can get started with your own functionality plugin.
Okay so first off, I’m in VS Code, which is the code editor I use. If you’re creating a functionality plugin for your website, you’re probably going to be using either FTP or the file manager that comes with your web hosting, which we’ll talk about at another time.
Anyway, inside of there you’ll want to go to the wp-content folder and then plugins folder, and then we’re going to create a new folder. And you can name it, sort of, the slug for your website like my hyphen business or something like that. That’s the title of my website. It doesn’t necessarily matter.
The key is now that we have the directory created, we’re going to create a new file. And our file, in order for it to be a WordPress plugin, needs to have the same slug as the folder we just created. And then we add in dot PHP because this will be a PHP file.
Boom. Done. And one more thing before this is officially a plugin, so we’ll go in here and put in this document header. So essentially what WordPress uses is this commented code to determine it’s a plugin and to get information about the plugin. So we have the plugin name. And then you can put in your URL to your website or whatever.
You don’t necessarily need the Plugin URI. You can put a description if you want. Really the most important parts are sort of the name, the version, license and text domain if you want it.
So now that we have a plugin, we can go into our WordPress website, and we should see it right here. We’re going to activate it. And then we’re just going to go over here and reload the page and nothing’s happened because obviously we have nothing inside of that plugin.
Okay so now to add in the login styles, we’re going to go back here and because I like to be nice and organized, I’m just going to add in a CSS directory and then a login dot CSS file. Okay now I’ve got my code in here for the CSS file. Save that. So now we’re going to load in the code that loads in our login dot CSS file when we’re logging in. Save that.
And there we go. We now have our login styles. And that is how you create a functionality plugin.
See it’s simple as that. Now you don’t have to worry about your customizations going away whenever you change themes because you will change themes; I guarantee it.
So what works best with a functionality plugin?
Well there’s the login styles that we just talked about, custom post types, custom taxonomies and anything that you want to change that directly involves WordPress and not the theme itself.
So try it out. Build it in a development environment if you can. But if you follow what I did, you should be good to go.
If you have any questions be sure to leave them down in the comments below. And if you want more WordPress tips and tricks be sure to subscribe. But until next time, happy WordPressing!