How to create a WordPress plugin from scratch?

Four steps:

  1. Make a folder in wp-content/plugins, like my-plugin.
  2. Add a PHP file with the same name. Write the header comment with at least Plugin Name.
  3. Write your code with hooks (actions and filters), a unique prefix and an ABSPATH check.
  4. Activate it from the Plugins screen (or wp plugin activate my-plugin).
<?php
/**
 * Plugin Name: TC Hello Plugin
 * Description: Adds a small text in the footer.
 * Version: 1.0.0
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

add_action( 'wp_footer', function () {
	echo '<p class="tchp">Made with WordPress</p>';
} );
Terminal output

$ wp plugin activate tc-hello-plugin
Plugin 'tc-hello-plugin' activated.
Success: Activated 1 of 1 plugins.
$ curl -s http://example.com/ | grep -o '<p class="tchp">[^<]*</p>'
<p class="tchp">Made with WordPress</p>

A full tested example with activation and uninstall is in Create a WordPress Plugin.


Learn more about the similar topics:
Tutorials
WordPress Plugins
WordPress Top Plugins List
WordPress SEO with Yoast SEO Plugin
Create a WordPress Plugin from Scratch
WordPress Plugin Settings Page (Settings API)
Exercises & Assignments
Write a plugin which adds a text to the footer
Interview Questions & Answers
What are the popular plugins in WordPress for SEO?
How to create a WordPress global options page?
How to create a WordPress plugin from scratch?
What is a plugin in WordPress? How is it different from a theme?
What is a must-use plugin (mu-plugin) in WordPress?