Quick Guide to Writing Your First Custom WordPress Plugin

Here’s how to create a Custom WordPress Plugin that adds an Event custom post type with options to manage events (All Events, Add New Event, Event Categories) in the admin panel.

Step-by-Step Guide to Create “Events” Plugin

1.Plugin File Structure

Create a folder in wp-content/plugins/ named:

custom-events-plugin

Inside that folder, create a file:

custom-events-plugin.php

2. Plugin Code (custom-events-plugin.php)

<?php
/*
Plugin Name: Custom Events Plugin
Description: A simple plugin to add and manage Events with categories.
Version: 1.1
Author: Your Name
*/

// Prevent direct access
if (!defined('ABSPATH')) exit;

// Register Custom Post Type: Event
function cep_register_event_post_type() {
    $labels = array(
        'name'               => 'Events',
        'singular_name'      => 'Event',
        'menu_name'          => 'Events',
        'name_admin_bar'     => 'Event',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Event',
        'new_item'           => 'New Event',
        'edit_item'          => 'Edit Event',
        'view_item'          => 'View Event',
        'all_items'          => 'All Events',
        'search_items'       => 'Search Events',
        'not_found'          => 'No events found.',
        'not_found_in_trash' => 'No events found in Trash.',
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'menu_icon'          => 'dashicons-calendar',
        'has_archive'        => true,
        'rewrite'            => array('slug' => 'events'),
        'supports'           => array('title', 'editor', 'thumbnail', 'custom-fields'),
        'show_in_rest'       => true,
        'taxonomies'         => array('event_category') // Connect taxonomy
    );

    register_post_type('event', $args);
}
add_action('init', 'cep_register_event_post_type');

// Register Custom Taxonomy: Event Category
function cep_register_event_category_taxonomy() {
    $labels = array(
        'name'              => 'Event Categories',
        'singular_name'     => 'Event Category',
        'search_items'      => 'Search Event Categories',
        'all_items'         => 'All Event Categories',
        'parent_item'       => 'Parent Category',
        'parent_item_colon' => 'Parent Category:',
        'edit_item'         => 'Edit Event Category',
        'update_item'       => 'Update Event Category',
        'add_new_item'      => 'Add New Event Category',
        'new_item_name'     => 'New Event Category Name',
        'menu_name'         => 'Event Categories',
    );

    $args = array(
        'hierarchical'      => true,
        'labels'            => $labels,
        'show_ui'           => true,
        'show_in_rest'      => true,
        'show_admin_column' => true,
        'rewrite'           => array('slug' => 'event-category'),
    );

    register_taxonomy('event_category', array('event'), $args);
}
add_action('init', 'cep_register_event_category_taxonomy');

3.How to Use

Upload the plugin folder custom-events-plugin to wp-content/plugins/

Activate the plugin in Plugins > Installed Plugins

You’ll now see a new Events menu in the WordPress admin with options:

  • All Events
  • Add New Event
  • Event Categories

Quick Guide to Writing Your First Custom WordPress Plugin

How to Set Up a Child Theme

Quick Guide to Writing Your First Custom WordPress Plugin

How to Create a Responsive Header that

Leave a comment

Your email address will not be published. Required fields are marked *