How to write a WordPress Plugin
In addition of having user base opportunities, you couldn’t refer WordPress as a mere platform for blogging but it’s that much potent to have capabilities regarding CMS. WordPress makes it possible to script anything what you need. You can extend the WordPress with the help of a WordPress plugin or a theme.
With the help of this tutorial, we are going to guide you about the way to write a
Hello World WordPress plugin, which is really easy to understand and to learn, even when you understand the basics of writing it.
The mandatory requirement is just of having a clear idea about PHP scripting.
Before I guide you about coding a WordPress plugin, please make sure that you recall the coding practices I’m going to write below:
Wherever and whenever you are going to comment, make it sure that you are commenting only if it is necessary.
Always try your best level to choose a plugin name which will not be matched with any other plugin name.
Test the WordPress Plugin
Make sure that your WordPress plugin is latest by testing your own local host with a latest version of WordPress.
WordPress Plugin Files And Names
One of the important part of plugin is to assign an unparalleled name, making document of plugin files and to organize the file.
We have an option to directly put the plugin PHP file into the
wp-content (WordPress plugins folder) but if you want to be in a list of good plugin developer creating a new folder is your ultimate need. Have a name as hello-world and place it within the
All the information about your WordPress plugin is there in the
readme.txt file and it is very convenient for you to deal with WordPress when the WordPress SVN plugin repository is submitted by you. Have a look on the readme sample.
Furthermore, just move on and establish these files, while the content will be added by us later on.
The basics Of WordPress Plugin
“Hooks” usually referred to as the heart of wordpress plugins. Basically are two functions, as given below:
One must know the difference between the above two functions as it is important part to know:
- add_action –> does an action at various points of WordPress execution
- add_filter –> filters the data (eg. escaping quotes before mysql insert, or during output to browser).
You may go through WordPress Plugin API if you want to understand it in a more exquisitely manner.
WordPress Plugin Information
After you open your
hello-world.php file, add the following commented plugin information in the first line of your file.
After saving this PHP file, go to your plugin folder then to
wordpress/wp-content/ and then to
plugins and place your plugin folder over here.
After you entered WordPress admin > plugins the new listed plugin is waiting for you to get activated.
What you think now? Isn’t it a simple task?