- Installing WordPress
- Basic knowledge PHP
First-Plugin.php PHP file code -
/ **
* Plugin name: First plugin
** /
?>
Now go to your WordPress dashboard-> Plugins.Here you can see our newly created plugin and its name.
We should not leave the description blank, as it helps the user know what the plugin is for. so let’s add a description of our plugin by adding a new comment line after “Plugin Name:” with the title “Description” and save it. PHP file code First-Plugin.php -
/ **
* Plugin name: First plugin
* Description: This is my first plugin.
** /
?>
We have successfully added our plugin description, now go to Dashboard-> plugin to see what it looks like.
Next we will add some functionality to our first plugin. We’ll add a basic function called first_plugin() that prints “HELLO This is my first plugin” and its shortcode that allows it to be placed on a WordPress post or page.
Code -
/ **
* Plugin name: First plugin
* Description: This is my first plugin.
** /
function
First_Plugin()
{
$content
=
" HELLO This is my first Plugin. "
;
return
$content
;
}
add_shortcode (
’ myplugin’
,
’First_Plugin’
)
?>
We use the WordPress shortcode function to display the output of this function. Go to Messages-> edit or create a new message. Add a shortcode for the plugin you just created.
Shortcode - [myplugin]
To see the output of the plugin, browse the website and open the post where we added our plugin shortcode.
This is how it looks
Now, to use this plugin functionality multiple times, we can use this shortcode multiple times. Just add the shortcode wherever we need this output.
Check message for updated output, here we get two identical suggestions because we used the shortcode in this post twice. We now have our plugin that returns a value and can be used anywhere using a shortcode.