A plugin adds functionality without changing files in the WordPress core. Although there is plenty of information on the basics of creating a custom WordPress plugin, I want to consolidate some of the most useful information below. Furthermore, the final plugin project files may be downloaded below.
/plugin-name
plugin-name.php
uninstall.php
/languages
/includes
/admin
/assets
/js
/css
/images
For instance, the folder structure to the left includes the main file, plugin-name.php, along with an uninstall.php file that is executed when a user removes a plugin. The admin folder separates admin functions from the public functions, so the admin code can be loaded for users with the appropriate role. The layout of your folder structure should be clear, however, you may require fewer folders depending on the complexity of your plugin.
The header of your main file should, at the very least, contain the Plugin Name. However, I recommend filling out the description and version lines as well. The commented section should appear at the top of your main plugin file.
To start, let's create a quick plugin that retrieves the most recent post and displays it using a WordPress shortcode.
In conclusion, WordPress allows us to expand functionality and tailor web content to fit our needs by creating your own custom WordPress plugin. In the next article, we will take a look at wp_enqueue_script() and wp_enqueue_style(). If you have any comments or suggestions, leave a comment below!