From the course: PHP for WordPress
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Creating a plugin
- [Instructor] Let's write a plugin. This plugin will create a redirect called Latest that sends users to the most recently published blog post. So let's get started. Here in our directory, I'm going to go to wp-contents and then plugins, and then I'm going to add a new file called latest-redirect.php. Now this is a really simple plugin that will be completely contained in one file, but most plugins will require a folder to house all of the files. The first thing I'm going to do is paste the plugin definition. Now, there are a few components to this. The first is the plugin name, which is what displays in the WordPress dashboard. So we're calling this Latest Post Redirect. A plugin URI, this is going to be a version of a plugin I've written previously, and then a description, version, author, author URL, license, and license URL. The next bit of code, which I also copied and pasted here, is to make sure this plugin file is not accessed directly. So we only want this to be accessed…
Contents
-
-
-
-
-
-
(Locked)
The functions file2m 53s
-
(Locked)
Copying Hello Dolly5m 3s
-
(Locked)
WP_Query4m 10s
-
(Locked)
Hooks, actions, and filters4m 41s
-
(Locked)
PHP in the Block Editor1m 29s
-
(Locked)
Theme development in the age of the Block Editor3m 3s
-
(Locked)
Creating a plugin10m 56s
-
(Locked)
Is PHP enough?1m 42s
-
(Locked)
-