In this blog we will learn how to create a custom plugin in wordpress. A plugin in wordpress is a set of re-usable code which helps us with any specific task. For instance, creating custom taxanomies, creating custom theme options etc.
I This blog we will aim to create a custom plugin which upon activation will automatically create a "custom post type" named "sample-post-type" in wordpress dashboard.Essentials Steps.A very basic plugin in wordpress comprises of a single php file which loads all the necessary functionality onto the dashboard over some default wordpress hook.1. To Allow the wordpress to recognize our plugin we would need a .php file. As per the wordpress standards the file shoud be located at "wp-content/plugins/<plugin-directory>". In our example we will be creating "sample-post-type.php" in "sample-post-type" directory inside "wp-content/plugins" folder.2. Upon creation, add the following code to the php file which allows wordpress to identify the plugin.The above mentioned code should be enough to display our plugin inside the "Plugins" tab in the dashboard.3. Now, to provide our plugin with the functionality to add custom post type we will add the following code to our php file over "init" hook using "add_action" method.
The above code upon activating the plugin will lead to the creation of a new custom post type in the dashboard as shown below.Thanks