Skip to content
HyperDAF editorialPlugin Tutorials

How to Create a WordPress Plugin (Your First One)

A WordPress plugin sounds like something only a developer can build. But a basic plugin is surprisingly small: one folder, one file, and a few lines of code. If you…

How to Create a WordPress Plugin (Your First One)
Plugin TutorialsEditor-curated guide
8 min5 sectionsIntermediate
Table of contents5

A WordPress plugin sounds like something only a developer can build. But a basic plugin is surprisingly small: one folder, one file, and a few lines of code. If you can copy and paste, you can create your first plugin today.

Why would you want to? Because a plugin is the clean way to add a small feature to your site. Instead of editing your theme — where your change disappears at the next theme update — you put the code in its own plugin, and it keeps working no matter what theme you use. This guide builds a tiny working plugin together, step by step, and explains every line in plain words.

What a plugin is (one folder, one file)

A plugin is a small package of code that adds a feature to WordPress. When WordPress loads your site, it looks in a folder called wp-content/plugins, finds the plugins you activated, and runs their code.

Every plugin has the same simple shape. There is a folder with the plugin’s name, and inside it a main file with the same name. That file starts with a short comment called the plugin header. The header tells WordPress the plugin’s name, its description, and its version. Without the header, WordPress does not know the file is a plugin at all.

A plugin can be as small as ten lines or as large as thousands of files. Big plugins do big jobs: shops, forms, memberships. But small plugins do small jobs just as well, and most of the plugins you will ever need are small: a line of text here, a small change there. The plugin we build in this guide adds a short message at the bottom of every page. It is a toy, but it is a real plugin — WordPress treats it exactly the same as any other.

One thing to understand before you start: a plugin is code, and code can break your site if it has a mistake. That is why you will build this first plugin on a test copy of your site if you have one, or at least make a backup first. A mistake in a small plugin is easy to fix — you just switch the plugin off — but a backup means you never have to worry.

Create the folder and the main file

First, decide the name of your plugin. Use small letters, no spaces, and dashes between words. We will call ours my-first-plugin. That name becomes both the folder name and the file name.

Open your hosting panel and find the file manager. Go to the wp-content folder, then into the plugins folder. Create a new folder called my-first-plugin. Then open that folder and create a new file called my-first-plugin.php. The .php ending matters: it tells the server the file holds PHP code.

Now open the file and paste this header at the top:

<?php
/*
Plugin Name: My First Plugin
Description: My first WordPress plugin — it adds a message at the bottom of every page.
Version: 1.0
Author: Your Name
*/

Let me explain each line. The first line, <?php, tells the server that PHP code follows. The lines between /* and */ are the header comment. Plugin Name is the name WordPress shows on your Plugins page. Description is the short text under the name. Version is 1.0 because this is your first version. Author is your name — put your real name or your site name here.

Save the file. You now have a plugin — but it does nothing yet. WordPress will already list it on your Plugins page, and you could activate it, but it would have no visible effect. The next step adds the part that does something.

Add your first function (step by step)

A function is a named block of code that does one job. Our plugin will have one function: it prints a short message. We then tell WordPress when to run it, using something called a hook.

Add these lines below the header you just pasted:

function my_first_plugin_message() {
    echo '<p>Hello from my first plugin!</p>';
}
add_action( 'wp_footer', 'my_first_plugin_message' );

Here is what each part does. The first line names the function my_first_plugin_message. The middle line is the job itself: echo means “print this”, and the text in quotes is a small piece of HTML — a paragraph with our message. The last line is the hook. add_action tells WordPress: when you reach the wp_footer moment — the bottom of every page, just before the page ends — run my function.

Hooks are the whole secret of WordPress plugins. WordPress runs through a long list of moments as it builds a page: the header loads, the content loads, the footer loads. A plugin hooks its functions onto those moments. You do not change WordPress itself — you just say “when you get to this moment, run my code too.” Once you understand hooks, every plugin becomes easier to read.

You can change the message to anything you like. Try your site name, or a line like “Thanks for visiting!” Save the file after every change.

Activate it and test it

Go to your WordPress dashboard and open the Plugins page. You will see “My First Plugin” in the list, with the description you wrote. Click Activate. WordPress turns your plugin on.

Now visit your site and scroll to the bottom of any page. You should see your message there: “Hello from my first plugin!” If you see it, congratulations — you built and activated a working WordPress plugin.

If you do not see the message, check three things. First, make sure the plugin is really activated — the Plugins page should show a Deactivate link under it. Second, check that you saved the file after adding the function. Third, look for a typo in the code: a missing quote or bracket stops the whole file. If your site shows an error after activating, do not panic — go back to the Plugins page and click Deactivate. The error goes away at once, because the code stops running.

When you install any plugin, the safe habits are the same: check where it came from, keep a backup, and test it after activating. Our guide on how to install WordPress plugins safely covers the full checklist, and if two plugins ever fight each other, our guide on troubleshooting WordPress plugin conflicts shows how to find the one causing the trouble.

What to build next + FAQ: do I need to know code?

Now that the pattern is clear — folder, file, header, function, hook — you can build many small things the same way. Here are three good next projects.

First, try a shortcode: a small tag like [my_message] that you can drop into any post. The code is only a few lines more than what you just wrote, and it teaches you how content and code connect. After that, the WordPress block editor is where your shortcode will appear on the page.

Second, try a dashboard widget: a small box on your admin dashboard that shows a reminder or a note. It uses a different hook, admin_notices or wp_dashboard_setup, but the shape is identical: a function, hooked to a moment.

Third, try a settings page: a simple page under Settings where you can type your message instead of editing the file. That one is bigger — it needs a form and a place to save the value — but it is the natural next step, and it is how real plugins let owners change things without touching code.

At HyperDAF, our own tools started as small plugins like this one — one folder, one file, one clear job. The big plugins you see in the world all began the same way: someone needed one small feature, built it, and then added the next feature, and the next.

Do I need to know code? A little PHP helps, but you do not need to be a programmer to start. You need to read code slowly, copy examples carefully, and change one thing at a time to see what happens. Every plugin developer started by copying a small example and changing the message inside it — exactly what you just did. Learn one hook at a time, keep your plugins small, and your skill grows with every one you build.

Your first plugin is done. It is small, it works, and it is yours. Build the next one.

Hayat Khan

Written by

Hayat Khan

Hayat Khan is the founder and owner of HyperDAF. He designs and develops HyperDAF's own WordPress themes, plugins and tools — every product on the platform is built, published and supported by his team, never resold from anyone else. He writes about WordPress, WooCommerce and building professional websites that are easy to run and maintain.

46 published articles
View all articles

Related articles

View all articles

Join the discussion

Your email address will not be published. Required fields are marked *

Keep comments relevant and respectful.