You can develop WordPress plugins with basic PHP, and you don’t need a framework to start. Below we walk through how to develop WordPress plugins from scratch, from setting up a local development environment and writing the plugin header to using hooks, building a working example plugin, handling security and publishing on WordPress.org. We also cover plugin architecture for larger projects, the requirements for the official directory and how to sell premium plugins.
Quick answer: To develop a WordPress plugin, create a folder in wp-content/plugins, add a PHP file with a plugin header comment containing at least Plugin Name, then use action and filter hooks to add your features. Activate it from the Plugins screen, test it with WP_DEBUG turned on and follow WordPress coding and security standards before sharing it.
Table of Contents
What You Need to Develop WordPress Plugins
To develop WordPress plugins, you need basic PHP, some HTML and CSS, a local WordPress site and a code editor. JavaScript helps for blocks and interactive features but isn’t required for simple plugins. Above all, you need to understand hooks, because almost every plugin works by attaching code to them.
Skills and Tools
| Need | Why | Examples |
|---|---|---|
| PHP basics | Plugins are written in PHP | Functions, arrays, classes |
| HTML and CSS | Output and styling | Admin pages, shortcodes |
| JavaScript | Blocks and interactive features | React for Gutenberg blocks |
| Code editor | Writing code | VS Code, PhpStorm |
| Local WordPress | Safe testing | Local, wp-env, DDEV, XAMPP |
| Version control | Tracking changes | Git and GitHub |
Plugin or Theme Code?
Put features in a plugin when they should keep working after a theme change, such as custom post types, tracking codes or business logic. Keep design code in the theme, as we explain in our guide to WordPress theme development.
Set Up an Environment to Develop WordPress Plugins
A good WordPress plugin development environment lets you write, break and fix code without touching a live site. Use a local WordPress install, turn on debugging and add tools that show errors and database queries. This setup catches most problems before your plugin reaches real users.
Local Environment Options
| Tool | Best for |
|---|---|
| Local (by WP Engine) | Beginners, one-click WordPress sites |
| wp-env | Developers using Docker and npm |
| DDEV | Teams that want consistent Docker setups |
| XAMPP or MAMP | Simple PHP and MySQL on your computer |
Our guide to WordPress local development compares these tools in more detail.
Debugging Settings
Add these lines to wp-config.php on your local site:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
Install Query Monitor to see PHP errors, hooks and database queries, and the official Plugin Check plugin to scan your code against WordPress.org standards.
WordPress Plugin Header and File Structure
Every plugin starts with a main PHP file containing a header comment. WordPress reads this header to show the plugin on the Plugins screen. Only Plugin Name is required, but a complete header with version, PHP requirements and license makes your plugin easier to maintain and publish.
Plugin Header Fields
| Field | Purpose |
|---|---|
| Plugin Name | Required, shown on the Plugins screen |
| Description | Short summary of what it does |
| Version | Current version number |
| Requires at least | Minimum WordPress version |
| Requires PHP | Minimum PHP version |
| Author and Author URI | Who built it |
| License | GPL-compatible license for WordPress.org |
| Text Domain | Used for translations |
| Requires Plugins | Other plugins it depends on |
The plugin header requirements page in the Plugin Handbook lists every field.
Typical File Structure
my-plugin/
my-plugin.php
uninstall.php
readme.txt
includes/
admin/
public/
assets/
languages/
Small plugins can live in one file. Larger plugins split admin code, public code and assets into folders, which keeps them easier to read and test.
How to Develop WordPress Plugins From Scratch: An Example
The fastest way to learn how to develop WordPress plugins is to build a small one. The example below adds an estimated reading time above every blog post. It uses a plugin header, a security check, a filter hook, translation functions and escaping, which covers the core skills you’ll use in bigger plugins.
Steps
- Create a folder named simple-reading-time in wp-content/plugins.
- Inside it, create simple-reading-time.php.
- Paste the code below and save.
- Go to Plugins in your dashboard and activate it.
- Open any blog post to see the reading time.
Example Plugin Code
<?php
/**
* Plugin Name: Simple Reading Time
* Description: Shows the estimated reading time above each post.
* Version: 1.0.0
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: Webzeto
* License: GPL-2.0-or-later
* Text Domain: simple-reading-time
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function srt_add_reading_time( $content ) {
if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$words = str_word_count( wp_strip_all_tags( $content ) );
$minutes = max( 1, (int) ceil( $words / 200 ) );
$label = sprintf(
_n( '%d minute read', '%d minutes read', $minutes, 'simple-reading-time' ),
$minutes
);
return '<p class="srt-reading-time">' . esc_html( $label ) . '</p>' . $content;
}
add_filter( 'the_content', 'srt_add_reading_time' );
The ABSPATH check stops anyone from running the file directly, and esc_html makes the output safe.
Using Hooks: Actions, Filters and Shortcodes
Hooks are how plugins change WordPress without editing core files. Actions run your code at a specific moment, such as when a post is saved. Filters change data before WordPress uses it, such as post content or titles. Shortcodes let users place your plugin’s output anywhere in their content.
Common Hooks for Plugins
| Hook | Type | Use |
|---|---|---|
| init | Action | Register post types and taxonomies |
| admin_menu | Action | Add settings pages |
| wp_enqueue_scripts | Action | Load CSS and JavaScript |
| save_post | Action | Run code when a post is saved |
| the_content | Filter | Change post content |
| the_title | Filter | Change post titles |
| add_shortcode | Function | Create a shortcode |
Learn Hooks in Depth
Our guide to WordPress hooks explains actions and filters with more examples. For plugins that talk to other apps, see how to code an API on WordPress.
WordPress Plugin Architecture for Larger Plugins
Simple plugins can use plain functions, but larger plugins need a clear architecture. Most professional plugins use classes, namespaces and Composer autoloading, separate admin and public code and keep business logic apart from templates. This structure makes code easier to test, extend and hand over to another developer.
Architecture Patterns
| Pattern | When to use it |
|---|---|
| Single file with functions | Small plugins under a few hundred lines |
| Class-based plugin | Medium plugins with settings and admin pages |
| Namespaces and Composer autoloading | Large plugins and team projects |
| Block plugin with @wordpress/create-block | Gutenberg blocks |
| WP-CLI scaffold | Quick starting files with tests |
Lifecycle Hooks
Use register_activation_hook to create options or database tables, register_deactivation_hook to clear scheduled tasks and an uninstall.php file to delete data when users remove the plugin. Clean uninstalls keep sites fast and users happy.
WordPress Plugin Security and Performance
Security mistakes in plugins are one of the most common ways WordPress sites get hacked. Every plugin should validate and sanitize input, escape output, check user permissions and use nonces on forms. For performance, load scripts only where needed and cache expensive queries.
Security Checklist
| Rule | Function to use |
|---|---|
| Sanitize input | sanitize_text_field(), absint() |
| Escape output | esc_html(), esc_attr(), esc_url() |
| Check permissions | current_user_can() |
| Verify forms | wp_nonce_field() and check_admin_referer() |
| Safe database queries | $wpdb->prepare() |
| Block direct access | ABSPATH check |
Avoid Breaking Sites
Test your plugin on current PHP versions and with popular themes and plugins. A single fatal error can trigger the WordPress critical error screen, so check the debug log before every release.
WordPress Plugin Requirements for WordPress.org
To publish on WordPress.org, your plugin must follow the directory’s guidelines and pass a manual review. It needs a GPL-compatible license, a readme.txt file in the right format and code that doesn’t track users without consent, hide links or obfuscate code. Approved plugins are managed through SVN.
Publishing Steps
- Read the detailed plugin guidelines.
- Run Plugin Check and fix any errors.
- Write a readme.txt with description, installation steps and FAQs.
- Zip the plugin and submit it on WordPress.org.
- Respond to the review team’s feedback.
- Upload approved code through SVN and tag releases.
Selling Premium Plugins
You can also sell plugins on CodeCanyon or your own site. Many developers offer a free version on WordPress.org and a paid upgrade, using tools like Easy Digital Downloads or Freemius for licensing and updates.
Learning Resources for Plugin Developers
The best free resource is the official WordPress Plugin Handbook, which covers everything from basics to security and publishing. Online courses on Udemy and other platforms add guided projects, while reading the code of well-built plugins teaches real patterns. Many developers save the handbook pages as PDF for offline reading.
Recommended Resources
| Resource | Best for |
|---|---|
| WordPress Plugin Handbook | Official, complete reference |
| WordPress Developer Resources code reference | Looking up functions and hooks |
| Learn WordPress tutorials | Free video lessons |
| Udemy plugin development courses | Structured paid projects |
| Open-source plugins on GitHub | Real-world code examples |
Hire a Plugin Developer
If you need a plugin built quickly or for business-critical work, hire an experienced WordPress plugin developer. Ask for code samples, security practices and how they handle updates and PHP compatibility, which our guide to preparing for WordPress PHP 8 covers.
FAQs
Here are answers to common questions about developing WordPress plugins.
How can I develop WordPress plugins from scratch?
Create a folder in wp-content/plugins, add a PHP file with a plugin header containing at least Plugin Name and activate it from the Plugins screen. Then use action and filter hooks to add features, test locally with WP_DEBUG turned on and follow security rules like sanitizing input and escaping output. Start with a small plugin and grow from there.
Do I need to be an expert coder to develop WordPress plugins?
No. Basic PHP, HTML and CSS are enough to build simple plugins, such as adding a shortcode, a tracking code or a content filter. You’ll need more advanced skills for complex plugins with settings pages, custom database tables or Gutenberg blocks. The WordPress Plugin Handbook and small practice projects are the best way to build those skills step by step.
What is the WordPress plugin header?
The plugin header is a PHP comment block at the top of your main plugin file. WordPress reads it to display your plugin on the Plugins screen. Plugin Name is the only required field, but most plugins also include Description, Version, Requires at least, Requires PHP, Author, License and Text Domain so users and site owners know exactly what they’re installing.
How long does it take to develop a WordPress plugin?
A simple plugin, like the reading time example above, usually takes an hour or two. A plugin with settings pages, custom post types and admin screens can take days or weeks. Complex plugins with integrations, payments or custom blocks can take months. Testing, security reviews and documentation usually take as long as writing the main code, so plan time for them.
What are the WordPress plugin requirements for WordPress.org?
Plugins listed on WordPress.org need a GPL-compatible license, a properly formatted readme.txt file and code that follows the directory guidelines. Plugins can’t obfuscate code, track users without consent, insert hidden links or include anything illegal or harmful. Every new plugin goes through a manual review by volunteers before approval, and updates are managed through SVN once the plugin is approved.
Can I sell my WordPress plugins?
Yes. You can sell premium plugins on marketplaces like CodeCanyon or on your own site using tools like Easy Digital Downloads or Freemius to handle payments, licenses and updates. Many developers publish a free version on WordPress.org to attract users, ratings and reviews, then sell a premium version with extra features, priority support and automatic updates for paying customers.
Do I need JavaScript to develop WordPress plugins?
Not for simple plugins, which can be written entirely in PHP with a little HTML. You’ll need JavaScript for interactive features, admin interfaces and especially Gutenberg blocks, which are built with React and the block editor APIs. Learning modern JavaScript and the @wordpress/scripts build tools is worth it if you plan to build block-based plugins or rich editor experiences for clients.
Where can I find a WordPress plugin development tutorial PDF?
The official WordPress Plugin Handbook is free online and you can save its pages as PDF from your browser for offline reading. It’s more current than most downloadable PDFs, which often show outdated code and insecure examples. Pair it with the Learn WordPress tutorials and a small practice project to apply what you read straight away and remember it longer.
Conclusion
You can develop WordPress plugins with basic PHP and a local WordPress site. Start with a folder in wp-content/plugins and a main file with a plugin header, then use action and filter hooks to add features. Build a small example first, like the reading time plugin above, follow security rules on every input and output and test with WP_DEBUG and Plugin Check before sharing your work.
Usman’s first twenty-line plugin outlived every theme change that client made, and that’s the real benefit of moving features into plugins. As your plugins grow, move to classes, clear file structures and lifecycle hooks, then publish on WordPress.org or sell premium versions to a wider audience. Keep the Plugin Handbook open as you code, update your plugins for new WordPress and PHP releases and write short docs so others can use them. What small problem on your site could your first plugin solve?











