Articles

My latest articles.

Categories

Creating a Simple Custom Plugin in WordPress

Skills

WordPress is incredibly flexible, largely thanks to its plugins. In this article, we’ll explore what plugins are, how to manage them, and even write a simple one yourself.

What is a WordPress Plugin?

A WordPress plugin is a piece of software that adds new functionality to your WordPress site. It can range from simple features like displaying a custom message to complex systems like e-commerce or SEO management.

  • Plugins help you extend WordPress without editing core files.
  • Thousands of free and premium plugins are available in the WordPress repository.
  • Common examples: contact forms, SEO tools, sliders, and security enhancements.

Think of a plugin as a “modular add-on” that can be installed or removed without breaking your website.

Enabling and Disabling Plugins

Managing plugins in WordPress is straightforward:

  1. Log in to your WordPress dashboard.
  2. Go to Plugins → Installed Plugins.
  3. Click Activate to enable a plugin or Deactivate to disable it.

💡 Tip: Always deactivate a plugin before deleting it. Some plugins store settings in the database, and deactivating first prevents potential issues.

Plugins vs functions.php

A common beginner question is:

“Should I put custom code in functions.php or write a plugin?”

  • functions.php:
    • Part of your theme.
    • Code here runs only while that theme is active.
    • Good for small tweaks tied to the theme.
    • Part of your theme.
    • Code here runs only while that theme is active.
    • Good for small tweaks tied to the theme.
    • Part of your theme.
    • Code here runs only while that theme is active.
    • Good for small tweaks tied to the theme.
    • Part of your theme.
    • Code here runs only while that theme is active.
    • Good for small tweaks tied to the theme.
  • Plugins:
    • Independent of the theme.
    • Can be activated/deactivated at will.
    • Ideal for site-wide functionality that shouldn’t be lost if you change themes.

✅ Rule of thumb: If your code is useful even after switching themes, use a plugin.

Writing a Simple Plugin

Let’s create a simple plugin that displays a “Hello, WordPress!” message at the top of every post.

  1. Create a Plugin Folder
    In wp-content/plugins/, create a new folder called hello-plugin.
  2. Create a Main PHP File
    Inside hello-plugin, create hello-plugin.php and add the following:
<?php
/*
Plugin Name: Hello Plugin
Description: Displays a friendly message.
Version: 1.0
Author: Your Name
*/

// Function to display the greeting
function hello_world() {
    echo "Hello, WordPress!";
};

hello_world();
  1. Note: Minimum requirement is to put the plugin name line in PHP comments.
  2. Activate the Plugin
    • Go to WordPress dashboard → Plugins → Installed Plugins.
    • Find Hello Plugin and click Activate.

Now, every single post on your site will start with a friendly “Hello, WordPress!” message.

Conclusion

Plugins are one of the most powerful features of WordPress. They allow you to:

  • Add new functionality without touching core files.
  • Keep code modular and portable across themes.
  • Enhance your site safely and efficiently.

By writing even a simple plugin, you gain a foundation to explore more advanced WordPress development. Once you’re comfortable, you can build plugins that do almost anything!