A WordPress plugin lets you add or change site functionality without editing your theme. For a first plugin, the safest approach is to build one small feature that is easy to understand, easy to test, and easy to disable if something goes wrong.
This guide walks through the basic plugin structure, a working example, and a few useful features you can add later. If you are still getting comfortable with WordPress administration, review WordPress for Beginners: Safe, Efficient Website Management Basics before editing plugin files.
What a WordPress plugin does
A plugin is a PHP-based package that extends WordPress. Themes mainly control presentation and templates, while plugins add features such as contact forms, SEO settings, custom post types, shortcodes, admin screens, or integrations.
That separation matters because a site feature should usually keep working even when the design changes. If the feature belongs to the site itself, put it in a plugin. If the change is mostly about layout, templates, or visual presentation, it is usually theme work. For appearance-focused development, see the related guide to creating a custom WordPress theme.
| Use a plugin when you need to | Use a theme when you need to |
|---|---|
| Add a feature, shortcode, admin page, integration, or custom site behavior. | Change templates, layouts, typography, colors, or the visual structure of pages. |
| Keep the feature available after switching to another theme. | Control how existing content and features appear to visitors. |
Before you start
Plugin work gives you direct control over site behavior, so prepare a safe place to experiment before changing a live site.
- Use a local or staging WordPress site. Build and test the plugin away from the live site first.
- Prepare file access. You need access to the
wp-content/plugins/directory through local files, FTP, or your hosting file manager. - Know the basics of PHP. A first plugin does not need advanced architecture, but you should understand functions, strings, comments, and simple WordPress hooks.
- Keep the first plugin small. One simple feature is easier to test, debug, and maintain than several features added at once.
- Plan how to disable it. If a test causes an error, you should know how to deactivate the plugin or remove its folder from
wp-content/plugins/.
A hook is a place where WordPress lets your code connect to its normal process. A filter changes a value and returns the new value. An action runs your code at a particular point. The examples below use both patterns in a small, controlled way.
Create a basic plugin
1. Create a plugin folder
In your WordPress installation, open the plugins directory and create a new folder for the plugin:
wp-content/plugins/my-first-plugin/
Use a lowercase folder name with words separated by hyphens. This keeps the folder easy to recognize and avoids confusion when the plugin grows.
2. Create the main plugin file
Inside the folder, create a PHP file with a matching name:
wp-content/plugins/my-first-plugin/my-first-plugin.php
This file is the entry point WordPress reads when it loads the plugin. For a small first plugin, keeping the code in one main file is enough. As the plugin grows, you can move related features into separate files.
3. Add plugin header information
Add a plugin header at the top of the main file. At minimum, WordPress needs a plugin name, but a short description, version, author, and license make the plugin easier to identify in the admin area.
<?php
/*
Plugin Name: My First Plugin
Plugin URI: https://example.com/
Description: Adds a small custom feature to WordPress.
Version: 1.0.0
Author: Your Name
Author URI: https://example.com/
License: GPL2
*/
| Header field | Why it helps |
|---|---|
Plugin Name |
Shows the plugin name on the Plugins screen. |
Description |
Explains what the plugin does, which is useful when you manage several plugins. |
Version |
Helps you track which copy of the plugin is installed. |
Author and License |
Make ownership and reuse terms clearer for future maintenance. |
After this header exists, WordPress can list the plugin on the Plugins screen.
4. Add simple functionality
For a first test, change the admin dashboard footer text. The admin_footer_text hook filters the footer text, so the callback should return the replacement text.
<?php
/*
Plugin Name: My First Plugin
Plugin URI: https://example.com/
Description: Adds a small custom feature to WordPress.
Version: 1.0.0
Author: Your Name
Author URI: https://example.com/
License: GPL2
*/
function my_first_plugin_admin_footer_text( $text ) {
return 'Thank you for visiting the admin dashboard!';
}
add_filter( 'admin_footer_text', 'my_first_plugin_admin_footer_text' );
The function name starts with my_first_plugin_ so it is less likely to conflict with another theme or plugin. The add_filter() line connects that function to the WordPress footer-text filter.
5. Activate and test the plugin
- Open the WordPress admin dashboard.
- Go to Plugins.
- Find My First Plugin.
- Select Activate.
- Check the admin footer and confirm the site still works as expected.
If the site shows an error, disable the plugin from the Plugins screen or remove the plugin folder from wp-content/plugins/, then review the PHP file for syntax mistakes.
| What you see | What to check first |
|---|---|
| The plugin does not appear on the Plugins screen. | Confirm the folder is inside wp-content/plugins/ and the main PHP file contains the plugin header. |
| The plugin appears but the message does not change. | Check the function name and the add_filter() line for spelling differences. |
| The site shows a PHP error. | Deactivate the plugin or remove its folder, then inspect the most recent code change. |
Useful features to add next
Once the basic plugin loads correctly, add one feature at a time. That makes it easier to tell which change caused a problem.
Add a shortcode
A shortcode lets editors place plugin output inside a post or page. The callback should return the content rather than print it directly, because WordPress decides where the returned content belongs in the post.
<?php
function my_first_plugin_message_shortcode() {
return '<p>This is a custom message!</p>';
}
add_shortcode( 'custom_message', 'my_first_plugin_message_shortcode' );
After adding this code, placing [custom_message] in a post or page will display the custom message.
Add an admin menu page
You can also add a simple admin page. Use a unique menu slug and check the user capability before outputting admin content. In this example, manage_options limits the page to users who should have administrative access.
<?php
function my_first_plugin_admin_menu() {
add_menu_page(
'Custom Menu',
'Custom Menu',
'manage_options',
'my-first-plugin-menu',
'my_first_plugin_admin_page'
);
}
add_action( 'admin_menu', 'my_first_plugin_admin_menu' );
function my_first_plugin_admin_page() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
echo '<div class="wrap">';
echo '<h2>Custom Menu</h2>';
echo '<p>This is the custom menu page.</p>';
echo '</div>';
}
This example creates a top-level admin menu item and displays a simple settings-style page for users with the required capability.
Plugin development best practices
- Prefix function names. Names such as
my_first_plugin_...reduce the chance of conflicts with WordPress core, themes, or other plugins. - Sanitize and verify input. Use functions such as
sanitize_text_field()for plain text input andwp_verify_nonce()when processing forms or actions. - Check permissions. Admin-only actions should confirm the current user has the required capability before showing or processing admin features.
- Keep code organized. As the plugin grows, separate features into smaller files or classes so maintenance stays manageable.
- Test updates carefully. Plugins can affect site security and stability, so test changes before deploying them to a live site. The related article on WordPress security covers broader maintenance habits for plugins, themes, accounts, and backups.
Summary checklist
- Create a folder inside
wp-content/plugins/. - Add a main PHP file with a clear plugin header.
- Register one small feature with the right WordPress hook.
- Activate the plugin from the WordPress admin screen.
- Test the result, then expand only after the first feature works.
Start with one focused function, use clear naming, and treat security checks as part of the first version rather than something to add later. Once the basics feel comfortable, you can expand into shortcodes, admin pages, settings screens, custom post types, or other features that fit your site.
WordPress plugin development support from greeden
Managing a WordPress site, including plugin development, can be challenging without the right expertise. greeden offers professional WordPress support for all user levels, from beginners to advanced developers.
What greeden offers
- Custom development: Tailored plugins to meet your unique requirements.
- Security management: Support for keeping plugins and the wider WordPress site safer and easier to maintain.
- Rapid issue resolution: Help with plugin-related errors, conflicts, and maintenance problems.
- Maintenance and updates: Ongoing support for WordPress, plugins, and site performance.
Whether you are new to WordPress or managing an established site, greeden can help you keep the technical side under control while you focus on growing your website.
Visit our contact page to learn more or get started today.
