Creating WordPress plugins lets you add custom features to your website. There are thousands of plugins available for free, and you can even create your own. This guide will show you how to create a WordPress plugin and start your plugin development journey step by step.
### What Do You Need to Create Your First WordPress Plugin?
WordPress plugins are like apps for your website. To make your first plugin, you need basic knowledge of coding languages like PHP, CSS, HTML, and JavaScript. It might sound like a lot, but don’t worry. This guide will take you through the process step by step, and by the end, you’ll understand enough to create a simple plugin.
You’ll also need a local development environment to test your plugin on your computer. Follow our guide on how to install WordPress on your computer (Windows or Mac). You can test your plugin on a staging website, but if an error occurs, it might break your site. Check out our guide on how to fix common WordPress errors for help.
You’ll need a plain text editor to write your code. Notepad or TextEdit works fine, but you can try more advanced code editors for developers if you prefer.
### Creating a Basic WordPress Plugin
1. **Create a Plugin Folder and File**:
– Create a new folder on your desktop or documents folder and name it something like `ewp-plugin-tutorial` or `my-first-plugin`.
– Create a new file in your text editor and save it inside your plugin folder as `ewp-plugin-tutorial.php` or `my-first-plugin.php`. The important part is the `.php` extension.
2. **Add Plugin Header**:
– Open the PHP file with your text editor.
– Add the following plugin header to tell WordPress about your plugin:
“`php
/*
Plugin Name: Plugin Tutorial
Plugin URI: https://ernestwebpro.com
Description: A short description of the plugin.
Version: 1.0
Author: Ernestwebpro
Author URI: https://ernestwebpro.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: wpb-tutorial
Domain Path: /languages
*/
“`
3. **Add Plugin Code**:
– Add the following code to display a message at the end of each article:
“`php
function ewp_follow_us($content) {
if (is_single()) {
$content .= ‘<p class=”follow-us”>If you liked this article, please follow us on <a href=”http://twitter.com/wpbeginner” title=”ernestwebpro on Twitter” target=”_blank” rel=”nofollow”>Twitter</a> and <a href=”https://www.facebook.com” title=” Facebook” target=”_blank” rel=”nofollow”>Facebook</a>.</p>’;
}
return $content;
}
add_filter(‘the_content’, ‘ewp_follow_us’);
“`
4. **Create a Zip File**:
– On your computer, create a zip file for the plugin folder. Right-click the folder and select ‘Compress’ to create a zip file.
### Installing and Activating Your First WordPress Plugin
1. **Upload and Install the Plugin**:
– Go to the WordPress admin area, navigate to Plugins > Add New, and click on ‘Upload Plugin’.
– Choose the zip file you created and click ‘Install Now’.
2. **Activate the Plugin**:
– After installing, activate the plugin. Visit your website to see the new message at the end of each post.
### Submitting Your Plugin to WordPress.org Plugin Repository
1. **Create a Read Me File**:
– Open a blank text file and save it as `readme.txt` in your plugin folder.
– Use the following template for your readme file:
“`markdown
=== Your Plugin Name ===
Contributors: ErnestWebPro
Tags: ErnestWebPro, plugin tutorial
Requires at least: 6.0
Tested up to: 6.2
Stable tag: 1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
A WordPress plugin to teach beginners how to write a WordPress plugin.
== Description ==
This simple plugin is part of our beginner’s guide to writing a WordPress plugin.
== Installation ==
1. Upload the plugin folder to your /wp-content/plugins/ folder.
2. Go to the **Plugins** page and activate the plugin.
== Frequently Asked Questions ==
= How do I use this plugin? =
Answer to the question.
= How to uninstall the plugin? =
Simply deactivate and delete the plugin.
== Screenshots ==
1. Description of the first screenshot.
2. Description of the second screenshot.
== Changelog ==
= 1.0 =
* Plugin released.
“`
2. **Submit Your Plugin**:
– Go to the Add Your Plugin page on WordPress.org and log in.
– Upload your plugin’s zip file and submit it for review.
### Using Subversion (SVN) to Upload Your Plugin
1. **Set Up SVN**:
– Install an SVN client like SilkSVN, TortoiseSVN (Windows), SmartSVN, or Versions App (Mac).
– Open the SVN client and create a new repository bookmark with your plugin’s SVN URL.
2. **Upload Plugin Files**:
– Add your plugin files to the trunk folder in your local repository.
– Commit the changes to sync your files with the WordPress.org repository.
### Adding Artwork to Your Plugin on WordPress.org
1. **Prepare Artwork**:
– Create a plugin header banner (772×250 or 1544×500 pixels) named `banner-772×250.jpg` or `banner-1544×500.jpg`.
– Create a plugin icon (125×125 or 250×250 pixels) named `icon-128×128.jpg` or `icon-256×256.jpg`.
– Add screenshots named `screenshot-1.png`, `screenshot-2.png`, etc.
2. **Upload Artwork**:
– Place the artwork in the assets folder of your local repository.
– Commit the changes to upload the artwork to WordPress.org.
Now you have a complete guide to creating, installing, and submitting a WordPress plugin. Happy coding!