Current Location: Home> Latest Articles> How to Create Your First ExpressionEngine Plugin: A Step-by-Step Guide

How to Create Your First ExpressionEngine Plugin: A Step-by-Step Guide

gitbox 2025-06-13

Introduction

ExpressionEngine (EE) is a powerful content management system known for its flexibility and scalability, making it a preferred choice for many web developers. EE not only provides various built-in modules and tags but also allows users to create plugins to extend its functionality. This article will guide you through the process of creating your first ExpressionEngine plugin, helping you understand how to leverage EE's plugin mechanism to increase productivity.

What is a Plugin?

In EE, plugins are a way to extend the system's functionality. They can handle complex logic, integrate with external services, and more. Plugins can be used anywhere in templates, control panels, static pages, etc., with just a simple tag call.

Plugin Types

EE plugins can be classified into the following types:

  • Standard Plugins: Used for handling basic logic.
  • Extension Plugins: Used to extend EE's core functionality, such as adding new widgets or handling URL rewrites.
  • Module Plugins: Plugins for EE's control panel.
  • Template Plugins: Plugins used for manipulating page templates, such as outputting dynamic content.

Creating a Plugin

After understanding the types of plugins, let's dive into how to create a standard plugin.

Step 1: Create Plugin Directory

Start by creating a new folder in EE's plugin directory to store the plugin you're about to create. The default plugin directory is usually located at /system/expressionengine/third_party/, but this can be configured in the system settings.

Step 2: Create Plugin File

In the newly created plugin directory, create a file with the same name as the plugin. The plugin file should include an EE_Plugin class that handles the plugin logic. Here's an example:


class My_plugin {
    // Plugin logic
}

Step 3: Configure Plugin Information

Within the plugin file, you need to configure basic information such as the plugin's name, version number, and whether caching is supported. This can be done using PHPDoc. Here’s an example:


/**
 * Plugin Name
 *
 * @package   My_plugin
 * @version   1.0.0
 * @author    Your Name
 * @link      [Your Website Link]
 */
class My_plugin {
    // Plugin logic
}

Step 4: Register Plugin

After configuring the plugin information, you need to register the plugin in EE so that the system knows about it. To register the plugin, simply add the following code to the main plugin file:


ee()->plugins->register('My_plugin', 'My_plugin');

The first parameter is the plugin name, and the second parameter is the class name defined in Step 2.

Plugin Example

Now, let’s create an example plugin that adds a custom tag to a template.

Step 1: Create Plugin Directory

First, create a plugin directory, such as: /system/expressionengine/third_party/my_plugin/.

Step 2: Create Plugin File

Within the /system/expressionengine/third_party/my_plugin/ directory, create a plugin file named my_plugin.php with the following content:


/**
 * My Plugin
 *
 * @package   My_plugin
 * @version   1.0.0
 * @author    Your Name
 * @link      [Your Website Link]
 */
class My_plugin {
    
    public $return_data = ''; // Initialize return value
    
    /**
     * Custom tag
     *
     * @access  public
     * @return  string
     */
    public function custom_tag()
    {
        $output = 'Hello World!';
        return $output;
    }
}

In this file, we've defined a My_plugin class and created a custom_tag() method that returns the string "Hello World!".

Step 3: Register Plugin

Once the plugin code is ready, register it in EE with the following code:


ee()->plugins->register('My_plugin', 'My_plugin');

Step 4: Use the Custom Tag

Now, in the template, you can use the custom tag you just created, like this:


{exp:My_plugin:custom_tag}

In this example, we’re calling the custom_tag() method from the My_plugin plugin, and the template will output "Hello World!".

Conclusion

Plugins are a powerful feature of EE, allowing you to handle complex business logic and extend the system in numerous ways. In this article, we’ve learned how to create a basic EE plugin. We hope this guide helps you get started with plugin development for EE.