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.
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.
/** * Plugin Name: WordPress.org Plugin * Plugin URI: https://example.com/plugins/the-basics/ * Description: Basic WordPress Plugin Header Comment * Version: 20160911 * Author: WordPress.org * Author URI: https://author.example.com/ * License: GPL2 * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Text Domain: wporg * Domain Path: /languages */
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!
SmugBits is all about web development and related fields. From web pages to web apps, we are always following the pursuit of learning something new and exciting. Along our adventure, we publish reviews, tutorials, and other bits of information we find along the way.