You don’t need to be a professional developer to write a WordPress plugin. A minimal plugin can start as a PHP file with an identifying header, but correct behavior still needs programming, testing, and maintenance. Once you understand that, every “add this to functions.php” tutorial becomes something you can package properly — in a plugin that survives theme changes.
This guide walks through building a simple WordPress plugin: what it needs, creating the file, adding a feature with hooks, adding a setting, and testing and sharing it.
At minimum, a plugin is one PHP file inside wp-content/plugins/ containing a header comment. That’s it — WordPress reads the header and lists it on the Plugins page.
Good practice for anything beyond a few lines:
my-first-plugin/my-first-plugin.php.<?php
/**
* Plugin Name: My First Plugin
* Description: Adds a small reading-time note to blog posts.
* Version: 1.0.0
* Author: Your Name
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Save it, upload the folder to wp-content/plugins/, and activate it in the dashboard. It does nothing yet — but it’s a real plugin.
Build locally while you experiment — see Local WordPress Development With Docker or LocalWP.
Add a reading-time note above post content using a filter:
function myfp_reading_time( $content ) {
if ( is_admin() || ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$words = str_word_count( wp_strip_all_tags( $content ) );
$wpm = max( 1, (int) get_option( 'myfp_wpm', 200 ) );
$minutes = max( 1, (int) ceil( $words / $wpm ) );
$note = '<p class="reading-time">' . $minutes . ' min read</p>';
return $note . $content;
}
add_filter( 'the_content', 'myfp_reading_time' );
Notice the prefix myfp_, the checks so it only runs on single posts, and the return — filters must always return a value. Hooks are explained fully in WordPress Hooks Explained: Actions and Filters for Beginners.
Let users change the words-per-minute value with a simple settings field:
add_action( 'admin_init', function() {
register_setting( 'reading', 'myfp_wpm', array(
'type' => 'integer',
'default' => 200,
'sanitize_callback' => 'absint',
) );
add_settings_field( 'myfp_wpm', 'Words per minute', function() {
printf( '<input id="myfp_wpm" type="number" min="1" name="myfp_wpm" value="%d" />', max( 1, (int) get_option( 'myfp_wpm', 200 ) ) );
}, 'reading', 'default', array( 'label_for' => 'myfp_wpm' ) );
} );
The calculation above now reads the saved setting and clamps its divisor to at least one. Browser input constraints are only a convenience; validate acceptable values server-side as the feature grows. Sanitise saved input and escape displayed output for its context.
A first WordPress plugin should do one small, understandable job. Keep the requirement narrow enough that you can describe the expected result and the cases where no change should occur. The reading-time example is a learning exercise, not a complete multilingual reading-time product or an independently tested production package.
Build locally or on staging with synthetic content and a recoverable backup. Keep independent hosting access available before activation. The article demonstrates source code and a review process; it does not install or execute the example on your website.
Write the requirement before adding code: display an approximate reading-time note for the main content of an ordinary single post. A WordPress plugin that modifies all content everywhere is broader than that requirement. Identify excluded contexts such as archives, feeds, API responses, or administrative output as relevant to the project.
State what the estimate means. Reading speed varies with language, technical complexity, formatting, and reader needs. The simple word-count function is not a reliable tokenizer for every language, and it does not measure comprehension or accessibility. Do not present the number as an exact promise.
Use one main file with a clear header and a uniquely named directory. The official header requirements identify Plugin Name as the minimum field and describe other metadata. Set requirements only after verifying them rather than copying a minimum PHP version without testing.
A WordPress plugin should have a meaningful version and an accurate author description. Keep source files organized in proportion to the feature. A one-purpose learning exercise does not need an elaborate framework, but it still benefits from clear names and a small maintained structure.
The content filter receives a value and should return a value on every relevant path. A WordPress plugin callback should preserve the original content when the condition does not match. Echoing a note from the filter is not the same as returning the transformed content to the caller.
Test the actual request contexts rather than assuming the conditions prove universal isolation. A theme or integration can apply content filters in unusual ways. Keep the requirement and acceptance tests together so a future change can be assessed against the original intended scope.
The saved speed must not create a zero divisor. A WordPress plugin should validate stored values and remain defensive when reading them, because configuration can change outside the visible input. Browser attributes such as min are useful for editing but are not server-side validation.
Decide the supported range and behavior for invalid input. For a production version, use a reviewed sanitization callback that accepts an appropriate integer range or returns a safe default. Test missing, zero, negative, excessively large, and unexpected values instead of checking only the initial value of 200.
Use supported Settings API behavior for the ordinary administration form and verify the intended capabilities. A WordPress plugin that adds custom handlers or endpoints needs explicit authorization and request protection for those routes. A nonce is not a substitute for checking what the user may change.
Escape dynamic output for its context and avoid inserting arbitrary user input into markup. The example’s integer formatting keeps that particular value numeric, but later additions such as a custom label or HTML template need their own handling. Review each new data path rather than assuming the first safe field protects the whole feature.
Activate, use, deactivate, and reactivate the WordPress plugin in a controlled environment. Check errors and verify that the note appears only where intended. Deactivation should stop the behavior without unexpectedly deleting user settings or unrelated content.
Understand the distinction between deactivation and uninstall. The lifecycle guide describes their different responsibilities. If permanent cleanup is added, document it clearly and follow supported uninstall handling rather than deleting business data when an administrator temporarily deactivates the feature.
Keep the source in version control and record the tested environment, required behavior, known limits, and recovery route. A WordPress plugin needs an owner after the first activation. Updates to PHP, WordPress, themes, and interacting components can change behavior even when the code is small.
Build a clean archive containing the intended plugin folder and runtime files. Exclude credentials, local logs, exports, and unrelated development material. Test the archive on a disposable site before sharing, and keep distribution separate from the act of writing a tutorial example.

The header makes WordPress recognize the file; it does not validate the feature. The direct-access guard prevents ordinary execution before WordPress defines its environment. The filter registration connects the callback to an execution point. Each part has a limited purpose and should be understood separately.
The reading-time calculation strips markup before counting words, then uses a saved speed value. A WordPress plugin built for multilingual publishing needs a more deliberate counting and formatting strategy. PHP’s simple word-count behavior can misrepresent scripts or words outside its supported assumptions.
The minimum result of one minute is a presentation choice, not a measured reading time. Empty content and a very short post therefore still produce that label under the demonstration rule. If the product requirement differs, define the new expected behavior and change the implementation accordingly.
| Case | Expected behavior to verify |
|---|---|
| Ordinary single post | One appropriate note appears with the main content |
| Archive or unrelated page | Original output remains unchanged where excluded |
| Missing setting | The documented default is used |
| Zero or invalid speed | No division error and a defined safe result |
| Different language | Known counting limits are acknowledged and tested |
| Deactivated plugin | The added note stops without losing unrelated content |
| Reactivated plugin | Expected configuration and behavior remain understandable |
Use the matrix to review the WordPress plugin rather than adding tests that merely repeat each source line. Check meaningful behavior and the failures the feature could cause. Record the actual results instead of marking the code tested simply because the example was read.

The demonstration attaches a field to the existing Reading settings page. Review the installed interface and save behavior. A WordPress plugin should use the supported settings registration, capability model, and validation for that workflow rather than processing arbitrary form submissions without checks.
Keep labels associated with their controls and provide understandable descriptions. If the setting affects only one feature, explain its units and default. An editor should not need to read PHP to know whether a value means words per minute, seconds, or a page-wide limit.
Separate input validation from defensive runtime reading. A value can be malformed through an old version, an import, a direct database change, or another integration. The calculation should still avoid a fatal condition and report or handle invalid configuration according to the product’s requirements.
Production-facing text should use an appropriate translation strategy and meaningful formatting. A WordPress plugin that hard-codes one English label can be acceptable as a limited teaching example but needs further work before being presented as a multilingual solution.
Test the language and content the site actually publishes. Word boundaries, numerals, reading direction, and plural forms can differ. A single English sample cannot establish correctness for Arabic, Chinese, or another writing system with different tokenization needs.
Keep estimates honest. If the feature cannot count a language reliably, document the limitation or choose a supported implementation. Do not substitute a confident-looking number for an unverified model merely to complete a user interface.
A small feature may need no special activation routine. Do not create database tables or flush rewrite rules without a reason. A WordPress plugin should perform only required setup and cleanup, with behavior that remains safe when the administrator activates it again.
Temporary deactivation is often part of troubleshooting. Preserve persistent user choices unless the documented design explicitly requires otherwise. The uninstall documentation explains the separate permanent-removal path and its supported protection.
If the feature later stores valuable records, define retention and deletion policy with the owner before adding cleanup. Removing an option used only for a speed setting has different consequences from dropping a table of customer submissions.
Test the theme’s actual rendering path and common interacting features. A WordPress plugin using the_content can encounter feeds, excerpts, builders, nested rendering, and other integrations depending on configuration. Conditions narrow the behavior but should be verified against the site rather than treated as a complete proof.
Check the editor experience and the front end as different surfaces. A note can appear correctly publicly while causing confusion in a preview or another application. Keep synthetic tests for these paths and inspect fresh errors after activation.
A unique prefix helps avoid naming conflicts, but it is not a complete compatibility strategy. Document dependencies, accepted values, and supported contexts. Keep the implementation small enough that another maintainer can understand why each condition exists.
Use protected logs and a reproducible action. If activation fails, inspect the exact error and restore the known working file through independent access. Do not repeatedly edit live PHP while visitors are using the site. A WordPress plugin can fail before the dashboard provides a normal recovery interface.
Check syntax, file encoding, function names, hook spelling, and the active environment. If the plugin loads but the note is absent, verify the request context and rendering path before changing unrelated settings. Preserve the input content on unmatched paths.
Remove temporary debugging after the issue is resolved and handle downloaded logs privately. Do not echo diagnostic values into an API response or expose private configuration on a public page. Keep a short incident note so the correction can be understood later.

Build a clean ZIP with one intended plugin directory and the files needed at runtime. Check that the main header and version are correct and that no secrets, private database exports, or unrelated project files are included. A WordPress plugin archive should be reviewed as a deliverable, not created from an entire development workspace by habit.
Install the archive on a disposable test site and repeat the meaningful acceptance cases. Verify the public description accurately states what the feature does and its limitations. Sharing privately and submitting to a public directory are separate actions with different review and maintenance requirements.
Follow the directory’s current guidelines if public distribution is intended. Do not claim approval or compatibility before it has been established. Keep a support and update plan proportional to the audience that will rely on the code.
If you need a maintained custom feature rather than a learning exercise, KAWEDMA offers website development and hosting services. Provide the required behavior, languages, user roles, dependencies, and recovery expectations. Ask for a tested handover with source, deployment steps, and known limits.
A useful WordPress plugin brief explains the problem and acceptance criteria rather than prescribing a copied snippet. That gives the implementer room to choose an appropriate hook, data model, and maintenance structure while keeping the result reviewable.
It identifies the file as a plugin, but production readiness also requires correct logic, permissions, validation, output handling, compatibility, recovery, and maintenance. Keep the demonstration’s scope separate from a complete supported product.
Usually temporary deactivation should not erase persistent user choices. Define cleanup deliberately and use the supported uninstall path for permanent removal where appropriate. Explain destructive behavior clearly before anyone depends on the stored data.
No universal language accuracy is established here. The simple counting method has limitations and the label is a teaching example. Use an appropriate tokenizer and translation strategy when the real requirement includes multilingual content.
The intended WordPress plugin behavior passes representative tests, excluded contexts remain correct, invalid settings do not cause failure, recovery is understood, and the owner has maintenance instructions. Record actual evidence and remaining limitations rather than relying on successful activation alone.
We may earn a commission on purchases made through these links, at no extra cost to you.
Don’t miss the chance to participate in the biggest giveaway of this year.