WordPress GuidePlugin → Create Plugin

How to create a WordPress plugin

Image

You don’t need to be a WordPress core contributor to build something powerful. Creating your own WordPress plugin lets you add features, optimize workflows, and even share your ideas with other site owners—without touching your theme or modifying WordPress files directly.

Let’s walk through the steps to create your first plugin, from folder setup to custom code to admin menus and publishing.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What is a WordPress plugin?

A WordPress plugin is a self-contained package of code that adds new functionality to your site. Plugins can do anything from adding a simple footer note to creating complex ecommerce or membership systems. They hook into WordPress’s core architecture to modify or extend its behavior without changing core files.

Most plugins are written in PHP and can also include JavaScript, CSS, HTML, SQL queries, or REST API functionality.

Why create your own plugin?

There are plenty of good reasons to roll up your sleeves and write a custom plugin:

Even if you’re not aiming for the plugin directory, custom plugins are a cleaner way to extend WordPress than stuffing functions into your theme’s functions.php file.

Step 1: Set up your plugin folder

Start by creating a new folder inside your WordPress installation at:

/wp-content/plugins/

Name your folder using lowercase letters and hyphens, like this:

custom-post-helper

Inside that folder, create a new PHP file with the same name:

custom-post-helper.php

Open the file and add a plugin header comment to tell WordPress what it is:

<?php
/**
 * Plugin Name: Custom Post Helper
 * Description: Adds helper functions for custom post types.
 * Version: 1.0
 * Author: Your Name
 */

This block is required. Without it, WordPress won’t recognize your plugin.

Step 2: Add your plugin code

You can now begin adding PHP code to define your plugin’s functionality. Let’s start with a simple example that adds a message to the footer of your site:

function my_footer_note() {
    echo ‘<p style=”text-align:center;”>Thanks for visiting!</p>’;
}
add_action(‘wp_footer’, ‘my_footer_note’);

The key concept here is hooks. WordPress uses actions and filters to allow plugins to run code at specific points. In the example above, add_action tells WordPress to run my_footer_note() when it reaches the wp_footer action.

Step 3: Activate your plugin

To activate your plugin, go to Plugins > Installed Plugins in your WordPress dashboard. You’ll see your plugin listed with its name and description. Click Activate to turn it on.

If something’s not working, make sure your PHP code doesn’t have syntax errors. You can enable debug mode by editing your wp-config.php file:

define(‘WP_DEBUG’, true);
define(‘WP_DEBUG_LOG’, true);

Any errors will be logged in /wp-content/debug.log.

Step 4: Add extra files (CSS, JS, etc.)

Most plugins will need more than one file, especially if they affect how your site looks or behaves in the browser. Common subfolders include:

To include CSS and JS files properly, use the wp_enqueue_scripts action:

function cph_enqueue_assets() {
    wp_enqueue_style(‘cph-style’, plugin_dir_url(__FILE__) . ‘css/style.css’);
    wp_enqueue_script(‘cph-script’, plugin_dir_url(__FILE__) . ‘js/script.js’, array(‘jquery’), null, true);
}
add_action(‘wp_enqueue_scripts’, ‘cph_enqueue_assets’);

This ensures your assets load only when needed and follow WordPress best practices.

Step 5: Add plugin settings or admin options

If your plugin needs user input—like a toggle, text field, or API key—you’ll want to add a settings page to the admin dashboard.

You can register a new menu item with add_menu_page():

function cph_register_menu() {
    add_menu_page(‘Post Helper Settings’, ‘Post Helper’, ‘manage_options’, ‘cph-settings’, ‘cph_settings_page’);
}
add_action(‘admin_menu’, ‘cph_register_menu’);

function cph_settings_page() {
    echo ‘<h1>Custom Post Helper Settings</h1>’;
    // Settings form will go here.
}

To store and retrieve settings, use update_option() and get_option(). If your plugin will have many settings, consider using the Settings API to handle saving and sanitizing user inputs.

Step 6: Test and debug your plugin

Before sharing or deploying your plugin, test it thoroughly in a safe environment.

Tips for testing:

Use error_log() to debug PHP functions:

error_log(‘My plugin function ran successfully.’);

Make sure your plugin doesn’t throw warnings, break other plugins, or slow down page loads.

Step 7: Publish or distribute your plugin

If you want to share your plugin, you have a few options:

To submit to the directory, you’ll need a readme.txt file following WordPress’s official format. This file includes plugin info, changelogs, installation instructions, and more.

Extra step: Organize your plugin for scalability

If your plugin grows beyond a few functions, take time to structure it properly:

Clean, modular code makes it easier to maintain and extend your plugin long-term.

FAQ

PHP is the main language used to write WordPress plugins. Most plugins also use JavaScript (for dynamic frontend features), CSS, and HTML. Larger plugins may include REST API endpoints or SQL queries.

If you’re building it yourself, the cost is essentially free—just your time. Hiring a developer can cost anywhere from $500 to $10,000+ depending on the complexity, features, and scope of the plugin.

Start by learning PHP and understanding how WordPress hooks, filters, and actions work. Practice by building simple plugins for personal use, then explore the Plugin Developer Handbook and contribute to open-source projects. Join communities like the Make WordPress Slack to keep learning and stay involved.

Yes, many developers run profitable plugin businesses. You can sell plugins on marketplaces, offer them freemium-style with paid add-ons, or build a subscription service. Success depends on solving a real problem, providing good support, and keeping your plugin updated.

Additional resources

What is a WordPress plugin? →

A complete beginner’s guide to WordPress plugins and how to manage them

WordPress speed optimization 101 →

Learn how to use performance tuning to fix five common problems and speed up your site.

How to check if a plugin is safe →

Simple steps to evaluating a plugin before you install and activate it