Sending Emails using PHPApril 28, 2018
SQL Joins TutorialMay 24, 2018
In this WordPress plugin tutorial, you’ll learn how to create a WordPress custom plugin from scratch. The most important reason to create a custom plugin is that it allows you to separate your own code from the WordPress core code.
You can write code for alter existing functionality provided by theme or wordpress plugin or for develop new functionality for your website.
You need to follow below steps to create a work your own custom plugin.
1. Creating Our First Plugin
First, create a folder in plugins directory and then create a single php file in that folder.
Here in this article I am creating plugin with name “myplugin”. So first I’ll create a folder with name myplugin in wp-content/plugins.
Inside this new folder, create a file with name myplugin.php. Open the file in a php editor, and paste the following code in this file:
wp_register_style('custom_css', plugins_url('style.css',__FILE__ ));
wp_register_script( 'custom_js', plugins_url('my_script.js',__FILE__ ));
add_action( 'wp_enqueue_scripts', 'myplugin_custom_scripts' );
Here in this code snippets only Plugin Name is required, other information other informations are optional.
Now you can activate plugin from WordPress admin by going to plugins page. Now you can write your PHP code in php file.
2. Structuring PlugIns
For manage complex functionality, we can create multiple folders and files.
If your plugin focuses on one main class, put that class in the main plugin file, and then add one or more separate files for other functionality.
You can also include custom JS and CSS files in the plugin main file to enhance the functionality of custom plugin. For include custom JS and CSS you can use below WordPress function.