How to Make a WordPress Plugin: A Beginner’s Guide
WordPress powers sites of all kinds, and plugins let site owners add features without changing the platform’s core code.
For people who manage a WordPress site, understanding how plugins are made can clarify how those features work and make it easier to create a small, tailored addition.
A first plugin can be simple, but it still needs to fit WordPress’s structure. This guide introduces the basics of making a WordPress plugin.
What You Need Before You Start
Before you start building a WordPress plugin, make sure you have a working WordPress site and access to its files. A Local WordPress setup is a safe place to test changes without affecting a live website.
You can use a local development tool to install WordPress on your computer, then open the site in a browser and confirm it works.
You’ll also need a way to access and edit your site’s files, such as a code editor and your computer’s file manager.
If you’re working on a hosted site, use its file access tools only when you understand how to avoid changing unrelated files.
Basic PHP knowledge helps you read and adjust plugin code. You don’t need to be an expert, but you should recognize variables, functions, and simple conditions.
Keep a backup before testing changes.
Create Your Plugin Folder and File
Create a folder for your plugin inside wp-content/plugins, then add a PHP file inside it. Use a short, descriptive name, such as reading-time, and keep the main file name consistent, like reading-time.php.
This simple plugin directory structure makes your files easier to find as your project grows.
- Open your site’s files with your hosting file manager or an SFTP app, then locate
wp-content/plugins. - Create a folder using lowercase letters and hyphens, avoiding spaces and special characters.
- Add a PHP file inside that folder, using the folder name for clear plugin file naming.
For example, your paths might be wp-content/plugins/reading-time/reading-time.php. Keep related files inside the plugin folder later, rather than scattering them across other directories.
For now, create just the folder and main PHP file; you’ll add the information WordPress needs next.
Add the Required Plugin Header
With your plugin folder and PHP file in place, add a plugin header at the top of the file so WordPress can identify and list your plugin in the admin area.
Add a plugin header to your PHP file so WordPress can identify and list your plugin in the admin area.
Open the PHP file and place the header inside a comment block before any other code. For example:
<?php
/**
* Plugin Name: Site Notes
* Description: Adds simple notes to your site.
* Version: 1.0.0
* Author: Your Name
*/Replace the sample name, description, and author with details that describe your plugin. Plugin author metadata helps users see who maintains it, so use a name or organization you want displayed publicly.
Choose plugin version numbering you can update as you release changes, such as 1.0.0 for your first release. WordPress reads these fields from the header, but it doesn’t require every optional field.
Keep the opening <?php tag first, and don’t add a closing PHP tag. Save the file, then check the Plugins screen to confirm WordPress lists your plugin.
Write a Simple WordPress Plugin
Once WordPress recognizes your plugin, add a small function to give it a clear purpose. Start with one task you can describe in a sentence, such as displaying a short message or storing a simple setting.
Keep the first version small, so you can check that it works before adding more.
Choose a practical task
Plugin use cases might include a custom notice, a basic site setting, or a small admin tool. Think about a repeated task you’d like to handle without editing your theme.
Custom plugin benefits include keeping your code separate from theme files, so it can stay in place when you change themes.
- Pick one task your plugin should handle.
- Write a short PHP function for that task in your plugin file.
- Save the file, then test the result on a staging site or a safe test installation.
Make sure your function has a clear name and doesn’t duplicate an existing plugin’s job.
Use a WordPress Hook to Add Features
To add features at the right time, connect your plugin’s function to a WordPress hook. A hook lets you run code when WordPress reaches a specific point, such as loading a page or saving a post.
Choose an action hook when you want to do something, or a filter hook when you want to change a value.
For example, add this line after defining your function:
add_action( 'wp_footer', 'my_plugin_add_message' );This tells WordPress to run my_plugin_add_message in the footer. The function is your callback, and the hook name identifies when it runs.
If your callback needs values from the hook, set its accepted argument count, then include those callback arguments in its parameters.
You can also set Hook priority to control order. Lower numbers run earlier; the default is 10.
Choose a priority only when timing matters.
Install and Activate Your Plugin
After you’ve added the plugin’s code, install it in WordPress and activate it to test its features. For a plugin you’re building, create a ZIP file containing its folder, then upload it through your site’s dashboard.
Once your plugin code is ready, install and activate it in WordPress to test its features.
- Open Plugins → Add New Plugin in your dashboard, then select Upload Plugin.
- Choose your ZIP file, click Install Now, and select Activate Plugin when WordPress finishes.
- Find your plugin in the installed plugins list, where you can deactivate it or review its details.
If you work locally, copy the plugin folder into wp-content/plugins, then activate it from the dashboard.
On a multisite network, consider Multisite plugin activation****: a network administrator can enable the plugin across all sites, or each site’s administrator can activate it separately.
Plan plugin update management too, so you can provide and install fixes as your code changes. Keep the ZIP and plugin folder organized for future updates.
Test Your Plugin Safely
With your plugin active, test it on a staging site or local copy before using it on a live site. This keeps mistakes away from visitors and protects your data.
Create a backup first, then use a test account with the same permissions as your typical users.
Check key features
- Try each feature in different situations, such as submitting an empty form, entering valid details, and viewing the result on a phone.
- Check that the plugin works with your WordPress version, active theme, and other common plugins.
- Review Test coverage by checking each feature and user role, not just the main workflow.
Check security and performance
Look for Plugin security risks: confirm that forms validate input, escape displayed content, and restrict actions by user role.
Watch page load times and check that your plugin doesn’t expose private data.
Keep notes on what you tested, so you can repeat the checks before future updates.
Fix Common Plugin Errors
When a plugin causes problems, disable other plugins one at a time to find conflicts.
Check your error logs for clues, such as a file name or line number. If you can’t access your site, deactivate the faulty plugin through your hosting file manager or FTP.
Debug Plugin Conflicts
Plugin conflicts can cause errors such as a broken layout, a failed update, or a WordPress site that won’t load. To find the cause, use Plugin Conflict Isolation, changing one thing at a time so you can identify the plugin involved.
- Back up your site. Save a recent copy before testing, and use a staging site if you have one.
- Deactivate plugins. Turn off all plugins except the one you’re testing. If the problem disappears, reactivate plugins one by one, checking your site after each change.
- Test your theme. Switch briefly to a default WordPress theme. This Theme Compatibility Testing can show whether the issue comes from your theme rather than a plugin.
Once you find the source, update it, replace it, or contact its developer. Test again before restoring changes on your live site.
Check Error Logs
If a plugin error persists after you’ve checked for conflicts, look at your site’s error logs for clues. Logs can show what failed, when it happened, and which file or plugin caused it.
Check Error Log Locations in your hosting control panel, or look for a debug.log file in your WordPress wp-content folder. Your host may also provide a separate PHP error log.
Read the entries
- Note the time the problem occurred, then find entries from that period.
- Check Log Severity Levels, such as notices, warnings, and fatal errors. A fatal error usually needs attention first.
- Look for your plugin’s name, a file path, or a line number. These details can point to the code that needs fixing.
- Share relevant entries with your host or a developer, but remove passwords and private data first.
Turn off debugging when you’re done, since logs may expose sensitive details.
Restore Plugin Access
If a plugin error blocks your access to the WordPress admin area, you can disable the plugin from your hosting control panel or with FTP, then sign in and fix the problem.
Restore Access
Use these steps for WordPress plugin lockout recovery:
- Open your hosting file manager or connect through FTP, then go to
wp-content/plugins. - Find the folder for the plugin causing the error. Rename it, such as adding
-disabledto its name. WordPress will deactivate it. - Return to your admin login page and sign in. If access returns, check your error logs, update the plugin, or contact its developer before reactivating it.
For plugin admin access restoration, rename the folder back only after you’ve corrected the issue.
If you’re unsure which plugin caused the lockout, rename plugin folders one at a time, testing access after each change.
Back up your files first when possible. Don’t delete plugin data unless you know you no longer need it.
Improve and Share Your Plugin
Test your plugin on different WordPress versions, themes, and hosting setups to catch issues early. Refine features based on what works and what users need.
When it’s ready, share it with the WordPress community and invite feedback.
Test Across Environments
Once your plugin works on your setup, check it in other WordPress environments before you share it. A plugin may behave differently when PHP versions, themes, or other plugins change. Test a few realistic setups, and record any errors you find.
- Test on hosting platforms: Install your plugin on a staging site with a different host or PHP version. Activate it, try its main task, then check the WordPress error log for warnings.
- Check browser compatibility: Open the plugin’s admin screens in current versions of Chrome, Firefox, Safari, and Edge. Confirm buttons, forms, and layouts work as expected.
- Check common combinations: Try a default WordPress theme, a popular third-party theme, and a site with other active plugins. Look for broken pages or conflicts, and note the steps that caused them.
Repeat key checks after fixes, so you know the plugin still works across environments before release.
Refine Plugin Features
With cross-environment checks complete, refine your plugin based on what you learned. Review test notes and user feedback, then look for patterns. Did several people struggle with the same setting? Did a feature fail on one WordPress version? Focus on problems that block common tasks before polishing small details.
Refine in three steps
- Sort issues: Group bugs, confusing controls, and feature requests. Record how often each issue appears and who it affects.
- Choose carefully: Use Feature prioritization to weigh user impact, effort, and risk. Fix security or data-loss issues first, then address frequent obstacles.
- Make focused changes: Update one area at a time, and retest affected workflows. Keep useful features stable, remove options that add needless complexity, and document any behavior changes for yourself.
Don’t add every requested feature. Confirm that each change supports your plugin’s purpose, fits your available time, and works reliably.
Share With The Community
Share your plugin with the community so other WordPress users can try it, report problems, and suggest useful improvements.
Start with a clear readme file that explains what your plugin does, how to install it, and which WordPress versions it supports. Then choose a place where users can find it, such as the WordPress Plugin Directory or your own website.
- Invite feedback: Ask users to describe the steps that led to a bug, and include your contact or support link.
- Review suggestions: Use Community feedback to spot repeated needs, then prioritize fixes that fit your plugin’s purpose.
- Welcome help: Make contributor outreach easier with setup notes, coding standards, and a short list of useful tasks.
Respond politely, even when you can’t make a suggested change. Test updates before releasing them, and note changes so users know what to expect.
Frequently Asked Questions
How Do I Submit a Plugin to the WordPress Plugin Directory?
You submit your plugin through the WordPress.org Plugin Review process: create an account, prepare your plugin to meet directory guidelines, then upload it through the Directory Submission form. Address reviewers’ feedback before approval and publication.
What License Should I Use for My Plugin?
Choose GPL-2.0-or-later for your plugin; it aligns with WordPress’s licensing requirements and simplifies GPL compatibility. For license selection, confirm every bundled dependency permits redistribution, and include the license text and copyright notices in your plugin files.
Conclusion
You can build a basic WordPress plugin with one PHP file, a valid header, and a hook that adds a clear feature. Start on a test site, then activate the plugin and check that it works without errors. If something breaks, review the file name, PHP syntax, and hook before adding more code. When you’re ready to share your plugin, document what it does, test it again, and keep the code focused and easy to maintain.
- Plugin development
- WordPress plugins
- WordPress testing
About the author
Vladimir Mrkela
Senior WordPress Developer
I’m a senior WordPress developer and co-founder of Pixel Industry. I’ve spent more than 12 years building websites, custom plugins, and integrations for all kinds of projects. I enjoy working on complex architecture, solving tricky problems, and sharing what I learn along the way.