FREELessons: 12Length: 1.3 hours

Next lesson playing in 5 seconds

Cancel
  • Overview
  • Transcript

2.1 Setting Up the Plugin

Hello, and welcome back to this Test Plus course on WordPress plugin development. In this part of the course, we're going to get started on our first plugin, and that will create section menus in the sidebar of our site. But first, I'll show you have to get set up with your plugin and your theme so everything will work for you. So you can see here, my dummy site, and it looks like I'm running 2016 but I'm actually running a child theme. And the reason for that is because I want to add code to some specific template files within the theme. You probably won't need me to tell you that coding a third party theme is a really bad idea, and the reason for that is because if you update the theme in the future, any changes you made will be completely lost. So you have to create a child theme if you want to do that. If you want to learn how to do that, here are some child themes tutorials and courses as well on the envatotuts+ website. So those will help you create your own child theme. But let me show you the code. So here in my WP content directory, I've got my themes folder. And within there, I've got 2017 and 2016, which were downloaded when I installed WordPress. And I've also got my child theme, which is called touch plus plugin development. Now that theme consists of a stylesheet, which you can see here has got the crucial line template 2016. And that tells WordPress this is a child theme of the 2016 theme. And also in my theme, there's a functions file that includes the style sheet from the parent theme, and that's the correct way to do it now. Now, my theme also includes some template files. I've got header.php, sidebar.php, and single.php. And those the files that I wanted to edit in 2016 but couldn't, so I created duplicates of them and I've added a line of code to each. So let me show you single.php to start with. So here, I've taken the 2016 single.php file, I've copied it into my child theme and I've added one line here, which is do action tutsplus after content. And that adds an action hooked, this template file at this particular point in the text. So if I write any functions later on and hook them to this action hook, the code output by the function will be output here in the page. And I'll show you it in action later on in the course. I've also added similar action hooks to the sidebar. So here you can see there's a tutsplus sidebar action hook, which we'll be using with this first plugin. And in the header.php file, I've added a tutsplus after header hook, which I've included as an option for one of the plugins that we'll be creating. So again, I duplicated header.php from 2016, and I just added that line of code. And because this is a child theme, this template file will override the same template file in the parent theme and so it will be used by any site using that theme. So I've got my site using the Tutsplus Plugin Development theme, which is a child theme of 2016, as it tells you here in the dashboard. So now let's start looking at our plugin. So the plugin that we'll be working with first is called Tutsplus Section Menus. And you can see here that it throws up an error. And that's because it doesn't contain a header yet, because I'm going to show you how to code it. So let's go back into our code. I'll close down the theme files, and here's my plugin file. Now let me just show you where that is in my files. So WP content plugins, and then there is a folder for the tutsplus section menus plugin. And within that, there's a file called tutsplus-section-menus.php. Now I'll show you how to set up the plug in file. So we start off by opening our PHP tag, and then we add a few lines of commented out text which will tell WordPress what this plugin is. So I've added the plugin name which will appear in the dashboard. The URL, which is a GitHub repository that I've created, which is here, so I'll copy its URL and paste that in to my header. The description, The version number. And I'm going to give this version number of the part in the course that we're currently on. And I'll change this for each part of the course so that you have an updated version of the to accompany each part of the course, the author. And obviously you would change this. Making sure I type my name correctly. The text domain which is for internationalization, and then finally the license, which must be the GPL. So that's my plugin set up with a header. So I'll save that, and then if I go back into my site, I'll find the tag and activate it again. So here it is, Tutsplus Section Menus. I'll activate that. But in the moment it won't do anything, because we haven't added any code to it. And that's what we'll do in the next part of the course. See you next time and thanks for watching.

Back to the top