Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
by
FREELessons:15Length:1.6 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

3.1 Setting Up the Plugin

In this lesson, you'll learn what you need to add to your plugin file to register it with WordPress.

Related Links

3.1 Setting Up the Plugin

Hello, and welcome back to this Tuts+ course on WordPress plugin development. In this part of the course, we're going to start writing a plugin. And I'll show you how to set up your plugin so that WordPress knows it's a plugin and can provide information about it in the admin screens. So here are a couple of resources that will help you with that. Firstly, the Codex page on writing a plugin. And secondly, our WordPress Coding Basics: Your First Plugin course. So here's my site and here's my Plugins page in the admin. Now at the moment, my plugin isn't showing up. And that's despite the fact that I have added the plugin file to the wp-content/plugins folder in my WordPress installation. But the reason it's not showing up is because I haven't added the commented out text that I need to, at the top, in order to set up the plugin. So here's the code, so if you look, I'm in wp-content and then plugins. And I've got a plugin here called tutsplus-sample-plugin. And that's just got one file in it at the moment. Now when you're creating a plugin, you can either just use one file for your plugin, as I've done with this plugin here, for example. Or you can use a folder and put your plugin file within there. And WordPress will automatically find the file that's got this commented out text, that we're about to add, and use that as the base file for the plugin. So anything else you add later on, such as include files and scripts and styles, will be caught via that base plugin file. It's a good idea to use folders because if you want to add more content later on, you can quite easily. But if you don't use a folder and you want to change later on, you could quite easily put your file within a folder and WordPress would still recognize it. So let's open my file. Now at the moment, this is an empty PHP file. So I need to add some commented out text to the top to tell WordPress that this is a plugin. So first, I'll add my opening php tags. I'm gonna need a slash and an asterisk to show that this is commented out text. The first field I use is Plugin Name. Then I'll have the Plugin URI. So that’s a link to where the plugin is stored. And that could be anything. That could be to your website. It could be to a GitHub repository, which is what I often use, or it could be to the documentation on your site. Or alternatively, it could be to the Plugins page in the WordPress plugin directory. It needs a Description. Making sure I type it correctly. Then we have the Author. The Author URI. The Version number. And normally, you'd start with 0.1 maybe for a development version and 1.0 for your first live version. I'm gonna call this version number 4.1 because that's the corresponding part of this course. The Text Domain is related to internationalization. So you add a Text Domain here, and then you use that within your internationalization functions to translate text. And then finally, the License, which is GPLv2. So that's my commented out text that tells WordPress a few things about my plugin. Now I'm gonna save that and have a look at the Plugins page in my admin screens. So I'll refresh the screen. And here it is, Tutsplus Sample Plugin. So I can now activate that if I want to. I'm not going to activate it cuz it doesn't do anything yet. But that shows you that this gives WordPress the information it needs to add your plugin to the Plugins page in the admin. So you can see we've got the description here. We've got the name here. We've got the author name with a link to my URI. And we've got a link here to the plugin URI as well, and the version number. So that gives WordPress everything it needs to run the plugin. So that's how you set up your plugin. In the next part of the course, I'm gonna show you how to add scripts and styles to a plugin. See you next time and thanks for watching.

Back to the top