Create a Custom WordPress Plugin in 2026: 7 Easy Steps

Custom WordPress plugin featured image by Pheonix Solutions showing the plugin header code and 7 easy steps to build your own plugin

Post Date:

Last Updated: November 26, 2026

Introduction

A custom WordPress plugin is the cleanest way to add your own features to a WordPress site. Instead of stacking third-party plugins or pasting snippets into your theme, you package exactly the code you need into one small, portable plugin that keeps working even when you change themes.

In this guide, you will create a custom WordPress plugin in 7 easy steps. You will build a working Simple Notice Bar plugin with a plugin header, a shortcode, a stylesheet, an admin settings page, proper security checks, and clean activation and uninstall code.

Key takeaways:

  • One header makes a plugin: a PHP file with a Plugin Name header is all WordPress needs to list your plugin.
  • Hooks do the work: actions and filters such as wp_enqueue_scripts and admin_menu connect your code to WordPress.
  • Security is not optional: check capabilities, use nonces, sanitize input, and escape output in every plugin.
  • Clean up after yourself: use activation and uninstall code so your plugin leaves no clutter behind.

At Pheonix Solutions, we build and maintain custom WordPress plugins for business websites, and this is the same structure we start every plugin with.

Why Build a Custom WordPress Plugin in 2026

Most WordPress sites only need a few small features that no off-the-shelf plugin does exactly right. Installing a large plugin for one feature adds extra code, extra updates, and extra risk. Pasting the code into your theme’s functions.php file is not much better, because the feature disappears the moment you switch themes.

Custom WordPress plugin diagram showing how WordPress loads the plugin file and runs its hooks for the shortcode, stylesheet, and settings page
  • Portable: a plugin keeps working across theme changes and can be reused on other sites.
  • Lightweight: you ship only the code your site needs, with nothing extra to load or update.
  • Maintainable: one folder with clear structure is easier to review, version, and hand over to another developer.
  • Secure by design: you control every input and output instead of trusting unknown third-party code.

Prerequisites for WordPress Plugin Development

Before you start, make sure you have the following ready:

  • A local WordPress site for testing. This guide uses the official wp-env tool, which needs Docker and Node.js.
  • WordPress 6.5 or newer and PHP 7.4 or newer.
  • A code editor such as Visual Studio Code or PhpStorm.
  • Administrator access to the WordPress dashboard.
  • Basic knowledge of PHP, HTML, and CSS.

7 Easy Steps to Create a Custom WordPress Plugin

You will build a Simple Notice Bar plugin. Site owners set a message in Settings → Notice Bar, and the shortcode [notice_bar type="success"] shows it anywhere on the site.

Step 1: Set Up a Local WordPress Environment

Never build a plugin on a live site. Create the plugin folder and start a local WordPress site from inside it with the official wp-env tool:

npm install -g @wordpress/env
mkdir simple-notice-bar && cd simple-notice-bar
wp-env start

When the command finishes, open http://localhost:8888/wp-admin and log in with the username admin and password password. Because you started wp-env inside the plugin folder, WordPress loads that folder as a plugin automatically.

Note: Make sure Docker is running before you run wp-env start. Run wp-env stop to shut the site down when you finish.

Step 2: Create the Plugin Folder and Main File

A plugin is a folder with one main PHP file. Use this structure:

simple-notice-bar/
├── simple-notice-bar.php    # main plugin file with the header
├── uninstall.php            # cleanup when the plugin is deleted
└── assets/
    └── notice-bar.css       # front-end styles

Open simple-notice-bar.php and add the plugin header. WordPress reads this comment to show your plugin on the Plugins screen:

<?php
/**
 * Plugin Name:       Simple Notice Bar
 * Description:       Shows a customizable notice bar anywhere with a shortcode.
 * Version:           1.0.0
 * Requires at least: 6.5
 * Requires PHP:      7.4
 * Author:            Your Name
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       simple-notice-bar
 */

// Stop the file from being loaded directly.
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

Only Plugin Name is required, but filling in the version, requirements, and license makes your plugin easier to maintain and share. Prefix every function with something unique, such as snb_, so your code never clashes with other plugins.

Step 3: Add a Shortcode

A shortcode lets editors place your feature anywhere in a post or page. Add this to the main plugin file:

function snb_render_notice_bar( $atts ) {
    $atts = shortcode_atts(
        array( 'type' => 'info' ),
        $atts,
        'notice_bar'
    );

    $allowed = array( 'info', 'success', 'warning' );
    $type    = in_array( $atts['type'], $allowed, true ) ? $atts['type'] : 'info';
    $message = get_option( 'snb_message', 'Welcome to our website!' );

    return sprintf(
        '<div class="snb-notice snb-notice--%1$s">%2$s</div>',
        esc_attr( $type ),
        esc_html( $message )
    );
}
add_shortcode( 'notice_bar', 'snb_render_notice_bar' );

The shortcode only accepts the types you allow and escapes the message before printing it. A shortcode must always return its HTML instead of echoing it.

Step 4: Load CSS the Right Way

Never hard-code <link> or <style> tags. Register your stylesheet with WordPress so it loads once, in the right place, and with a version number for caching:

function snb_enqueue_assets() {
    wp_enqueue_style(
        'snb-notice-bar',
        plugins_url( 'assets/notice-bar.css', __FILE__ ),
        array(),
        '1.0.0'
    );
}
add_action( 'wp_enqueue_scripts', 'snb_enqueue_assets' );

Then add the styles in assets/notice-bar.css:

.snb-notice { padding: 12px 16px; border-radius: 6px; margin: 16px 0; }
.snb-notice--info    { background: #e8f1ff; color: #1f3b73; }
.snb-notice--success { background: #e7f8ee; color: #166534; }
.snb-notice--warning { background: #fff6e5; color: #92400e; }

Note: Increase the version number in wp_enqueue_style() every time you change the CSS, so browsers and caching plugins load the new file instead of an old copy.

Need a feature no plugin offers? Our WordPress developers build lightweight, secure custom plugins that fit your exact workflow. Talk to our WordPress plugin experts for a free consultation.

Step 5: Add an Admin Settings Page

Let site owners change the message without touching code. The Settings API registers the option, handles saving, and adds security fields for you:

function snb_add_settings_page() {
    add_options_page(
        'Notice Bar',            // page title
        'Notice Bar',            // menu title
        'manage_options',        // required capability
        'simple-notice-bar',     // menu slug
        'snb_render_settings_page'
    );
}
add_action( 'admin_menu', 'snb_add_settings_page' );

function snb_register_settings() {
    register_setting(
        'snb_settings',
        'snb_message',
        array(
            'type'              => 'string',
            'sanitize_callback' => 'sanitize_text_field',
            'default'           => 'Welcome to our website!',
        )
    );
}
add_action( 'admin_init', 'snb_register_settings' );

function snb_render_settings_page() {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    ?>
    <div class="wrap">
        <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
        <form action="options.php" method="post">
            <?php settings_fields( 'snb_settings' ); ?>
            <label for="snb_message">Notice message</label>
            <input type="text" id="snb_message" name="snb_message" class="regular-text"
                   value="<?php echo esc_attr( get_option( 'snb_message' ) ); ?>">
            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}

The new page appears under Settings → Notice Bar. settings_fields() prints the hidden nonce and option fields, and sanitize_text_field cleans the message before it is saved.

Step 6: Secure Your Plugin

Every custom WordPress plugin should follow five rules. The Settings API already covers most of them, but you need them yourself whenever you process your own forms or requests:

Custom WordPress plugin security checklist showing direct access guard, capability checks, nonces, input sanitization, and output escaping
  • Block direct access: the ABSPATH check from Step 2.
  • Check capabilities: use current_user_can() before showing or saving admin data.
  • Verify nonces: confirm the request came from your own form.
  • Sanitize input: clean every value before you save it.
  • Escape output: use esc_html(), esc_attr(), or esc_url() when printing.

If you build your own form instead of using the Settings API, add and verify a nonce like this:

// In the form:
wp_nonce_field( 'snb_save_message', 'snb_nonce' );

// When processing the request:
if ( ! current_user_can( 'manage_options' ) ) {
    wp_die( esc_html__( 'You are not allowed to do this.', 'simple-notice-bar' ) );
}

if ( ! isset( $_POST['snb_nonce'] )
    || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['snb_nonce'] ) ), 'snb_save_message' ) ) {
    wp_die( esc_html__( 'Security check failed.', 'simple-notice-bar' ) );
}

$message = sanitize_text_field( wp_unslash( $_POST['snb_message'] ?? '' ) );
update_option( 'snb_message', $message );

Step 7: Activate, Test, and Package the Plugin

Add an activation hook to the main file so the plugin sets its default value the first time it is activated:

function snb_activate() {
    add_option( 'snb_message', 'Welcome to our website!' );
}
register_activation_hook( __FILE__, 'snb_activate' );

Create uninstall.php so the plugin removes its data when someone deletes it:

<?php
// Runs only when the plugin is deleted from the Plugins screen.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
    exit;
}

delete_option( 'snb_message' );

Activate the plugin from Plugins → Installed Plugins, or from the terminal with WP-CLI inside wp-env:

wp-env run cli wp plugin activate simple-notice-bar

Add [notice_bar type="success"] to any page, set your message in Settings → Notice Bar, and view the page. When everything works, package the plugin as a ZIP file that you can upload to any WordPress site:

cd ..
zip -r simple-notice-bar.zip simple-notice-bar -x "*.DS_Store" -x "*/node_modules/*"

Note: Upload the ZIP from Plugins → Add New Plugin → Upload Plugin on your staging site first. Test it there before installing it on a live site.

Output

With the message set to “Free shipping on all orders this week!”, the shortcode [notice_bar type="success"] prints this HTML on the page:

<div class="snb-notice snb-notice--success">Free shipping on all orders this week!</div>

Visitors see a green notice bar with your message, and editors can change the text at any time from Settings → Notice Bar without touching any code.

Conclusion

A custom WordPress plugin gives you exactly the features your site needs, in one small folder that survives theme changes. In 7 easy steps, you set up a local site, wrote the plugin header, added a shortcode, loaded CSS correctly, built a settings page, secured the code, and packaged it for release.

  • Start with the header: one PHP file and a Plugin Name are enough to begin.
  • Use hooks: connect your code to WordPress with actions, filters, and shortcodes.
  • Use WordPress APIs: the Settings API and wp_enqueue_style() save time and avoid conflicts.
  • Secure everything: capabilities, nonces, sanitizing, and escaping in every plugin.
  • Clean up: activation and uninstall code keep the database tidy.

FAQs

1. Do I need to know PHP to create a WordPress plugin?

Yes, basic PHP is enough for a simple plugin like the one in this guide. Knowing HTML and CSS helps for the front-end output, and JavaScript is useful if your plugin adds blocks or interactive features.

2. Should I add custom code to functions.php or a plugin?

Use a plugin for any feature that should keep working when you change themes, such as shortcodes, custom post types, or integrations. Keep only theme-specific design code in functions.php.

3. Can I publish my custom WordPress plugin on WordPress.org?

Yes. Plugins in the WordPress.org directory must use a GPL-compatible license, follow the plugin guidelines, and pass a manual review. You can also keep a plugin private and install it from a ZIP file.

4. How do I keep a custom WordPress plugin secure?

Block direct file access, check user capabilities, verify nonces on every form, sanitize all input, and escape all output. Keep the plugin updated and test it on a staging site before each release.

5. Will a custom plugin slow down my website?

Not if it is built well. A small plugin that loads only what it needs is usually lighter than a large general-purpose plugin. Load scripts and styles only on the pages that use them.

Official Documentation

Talk to WordPress Experts

Off-the-shelf plugins rarely fit a business perfectly, and the wrong ones can slow your site down or open security gaps. At Pheonix Solutions, our team has more than 10 years of experience building fast, secure WordPress websites and custom plugins.

We can help you with:

  • Website development, including custom WordPress plugins and themes built for your workflow.
  • Reviewing and fixing existing plugins for security, performance, and compatibility issues.
  • VPS hosting tuned for fast, reliable WordPress sites.
  • Software maintenance and support to keep your plugins updated and secure.

Have a feature in mind for your WordPress site? Talk to our WordPress experts and get a free consultation on your custom plugin.

Pratismith

Pratismith is a mobile app developer at Pheonix Solutions who builds iOS and Android apps with Kotlin Multiplatform and native Android. Pratismith writes practical, step-by-step guides on mobile app development, cross-platform architecture, and shipping apps to the App Store and Google Play.

Leave a Comment

Scroll to Top