WordPress plugins allow you to add new features to your website without changing the core WordPress files. In this tutorial, I will show you how to create your first WordPress plugin step by step, even if you are a beginner.
By the end of this guide, you will have a working custom plugin that adds a feature to your site.
Table of Contents
Toggleβ What You Need
-
A WordPress website installed
-
Access to your hosting file manager or FTP
-
Basic knowledge of PHP (not required, but helpful)
π Step 1: Create Plugin Folder
Go to:
/wp-content/plugins/
Create a new folder:
my-first-plugin
π Step 2: Create Main Plugin File
Inside that folder, create a file:
my-first-plugin.php
π§ Step 3: Add Plugin Header Code
Open my-first-plugin.php and paste this:
<?php
/**
* Plugin Name: My First Plugin
* Plugin URI: https://yourwebsite.com
* Description: This is my first WordPress plugin.
* Version: 1.0
* Author: Your Name
* Author URI: https://yourwebsite.com
*/
Save the file.
π Step 4: Activate the Plugin
Go to:
WordPress Dashboard β Plugins β Installed Plugins
You will see:
My First Plugin
Click Activate.
π Congratulations! You have created your first WordPress plugin.
π Step 5: Add a Simple Feature
Now letβs make the plugin do something.
Add this code below the header:
add_action('wp_footer', 'mfp_show_message');
function mfp_show_message() {
echo ‘<p style=”text-align:center;color:green;”>My First Plugin is working!</p>’;
}
Save the file and refresh your website.
β You will see a message in the footer of your site.
π§ͺ How This Works
-
add_action()connects your function to WordPress -
wp_footerruns when the footer loads -
echoprints text on the screen
π¦ Final Plugin Code
Your complete file should look like this:
<?php
/**
* Plugin Name: My First Plugin
* Plugin URI: https://yourwebsite.com
* Description: This is my first WordPress plugin.
* Version: 1.0
* Author: Your Name
* Author URI: https://yourwebsite.com
*/add_action(‘wp_footer’, ‘mfp_show_message’);
function mfp_show_message() {
echo ‘<p style=”text-align:center;color:green;”>My First Plugin is working!</p>’;
}
π What You Learned
-
How WordPress plugins work
-
How to create a plugin folder and file
-
How to register a plugin
-
How to add functionality using hooks
π Whatβs Next?
In the next tutorial, we will learn:
-
How to add admin menu to a plugin
-
How to create plugin settings page
-
How to build real plugins
π Conclusion
Creating a WordPress plugin is not difficult if you understand the basics. This is your first step into WordPress plugin development.
If you have any questions, feel free to ask in the comments.
No related posts.