How to code a very simple WordPress plugin from scratch (2019)

Saul Goodman June 3, 2019 Loading...

This tutorial will show you how to create a very simple and stupid WordPress plugin form scratch.

Prerequisites:

  • A WordPress website installed on your localhost or an online server
  • Basic PHP knowledge
  • A code editor (Notepad, VS Code, Subline Text…)

Step 1: Go to your WordPress installation folder and navigate to /wp-content/plugins

Step 2: Create a new folder and call it my-plugin or whatever name you want.

Step 3: Create a php file inside the folder that you has created in step 2 and name it index.php . Add the following code into the php file:

<?php
/*
Plugin Name: My Simple Plugin
Plugin URI: https://www.kindacode.com (or your own uri)
Author: Donald Trump (or whatever name you like)
Author URI: https://www.kindacode.com (replace with your own profile uri)
Version: 1.0.0
Description: The best WordPress plugin in the world that loved by everyone
License:     GPL2 etc
*/

Save the index.php file and jump into WordPress Dashboard > Plugins > Installed Plugins. Your new plugin must be listed here.

Step 4: Though your plugin was successfully created, it does nothing. Go back to the index.php file created in step 3 and add some lines of code into it like this:

<?php
/*
Plugin Name: My Simple Plugin
Plugin URI: https://www.kindacode.com (or your own uri)
Author: Donald Trump (or whatever name you like)
Author URI: https://www.kindacode.com (replace with your own profile uri)
Version: 1.0.0
Description: The best WordPress plugin in the world that loved by everyone
License:     GPL2 etc
*/

function my_test(){
    echo '<h1 style="padding: 30px; font-size: 50px; text-align: center; color: red">This paragraph was generated by My Simple Plugin</h1>';
}
add_action('wp_footer', 'my_test');
?>

Now view your website in Chrome or Firefox and have a look at the bottom of the page. You will see something like this:

Congratulations! You have created your first WordPress plugin from scratch. It may seem like a useless plugin because I tried to make this tutorial as basic as possible. At this point, you are pretty much good to go.

avatar
Welcome to KINDACODE. Have a nice day and code well!