You are certainly wondering why I propose a tutorial quite difficult to understand. The reason is that as a WordPress user or developer, we always have to modify the behavior of WordPress especially by using the plugins.

However, any modification of the behavior of WordPress does not necessarily give place to a configuration interface, hence the notion of " out-of-the-box ". And very often, for the activation or deactivation of a WordPress feature, a few lines of code suffice.

In reality, add these codes in the active theme file (functions.php) is a good idea, but it is not a good idea when the theme is updated automatically or when you change the theme, hence the initiative to create your own plugin.

What are the prerequisites?

A priori for a basic plugin, I'll say, " you only need to be attentive ". You do not need anything to the extent that I will provide you with quite detailed codes on some " hacks Of WordPress, and you will simply copy them to the main file of your plugin.

If you plan to create complete plugins, then you will need to learn how to use "PHP / Mysql" on the one hand and master the "API" of WordPress (Interface Programming Interface).

You must also remember that we are in a test situation and for good reason, you must have a specific environment installed at home or online, but this environment should not be used for production.

Basically don't test what you are going to learn on your blog principal.

Creating a simple plugin

All you need to do is to create a folder named as you want containing a file with the same name, but written under the extension " . Php ».

In this exercise, we will create a file named " plugin-wordpress.php »Included in a folder« plugin-wordpress That we are going to copy somewhere on our computer.

wordpress plugin-image

Open this file with a text editor of your choice. But I advise you to install "notepad ++", which is lightweight and very easy to use.

Start by writing an opening php tag <? php ". This is how any php file starts. The closing tag (?>), it's not mandatory.

beginning-of-the-drafting

Once done, we will create the file header. For that, you must first open the comments. That is, using " /* And closing with " */ ».

change-plugin

Now that the header is ready, we will define the plugin information, including:

  • The plugin name (Plugin Name: Example of WordPress Plugin)
  • the plugin description (Description: your description)
  • the name of the author (Author: Your name)
  • The plugin version (Version: 1.0 or 2.0 at your leisure).

plugin-details

This is basic information, but other information is available on the WordPress Codex.

Once it's done ... well, your plugin is ready, but it's not doing anything for the moment. You can now compress your plugin in the " zip And install it on WordPress. Yes yes, you can do it. Here is what your plugin will look like once installed.

exmple de plugin

It's in the file plugin-wordpress.php That you will add your different PHP codes that I will propose to you in the future or yours.

That's it for this tutorial on creating a simple WordPress plugin.