Creating a plugin on WordPress is one of the most simplest things to do and it has many advantages over customizing the theme code.
When we want to customize or add some functions to our theme, we normally struggle trying to add the code directly to the theme functions.php. Instead, with some creativity we can manage to add our own plugin and test the new functions there, instead of directly on the code.
Advantages: If we mess with the theme’s functions.php, the whole page could break. If we do something wrong inside our custom plugin, wordpress will deactivate and the page will be still alive.
For creating our own plugin, we only have to create one folder and one file on the /wp-content/plugins/ folder.
We are going to create the file myplugin.php and place it inside the folder ‘myplugin’. Inside the file we’re going to place this content:
<?php /* Plugin Name: My Plugin Plugin URI: http://developer.infoymas.com Description: This plugin prefill the content for new posts Version: 0.10 Author: Developer Author URI: http://developer.infoymas.com License: GPLv3 */ ?>
This tells wordpress that a new plugin is installed and that it’s name is ‘My Plugin’. Obviously you can change this to whatever you want the plugin to be named.
After that, we just have to upload the file and go to the Plugins Manager inside the wordpress administrator
We’re going to see it deactivated on the list of plugins:
After it’s recognized by wordpress, we can start coding inside the PHP file we just created. This is specially useful when we want to add functions to the functions.php of our theme. Instead of just copying and pasting on the functions.php whatever function we want to try, we can create a plugin and avoid deleting or modifying by mistake some other important functions of our theme.
Now open this link to start using your plugin: Creating default content for new posts with a custom plugin