Manually Creating WordPress Plugins:

Fri, 29 Dec 2023 06:58:44 +0000

Creating your own WordPress plugin allows you to tailor functionalities to your specific needs. Here's a simple example of creating a basic plugin:

1. Create a New Folder:

Create a new folder in the wp-content/plugins/ directory of your WordPress installation. Name it something unique and descriptive, like my-custom-plugin.

2. Create the Main Plugin File:

Inside your new folder, create a main PHP file. For example, my-custom-plugin.php. This file should contain basic plugin information and hooks:

<?php
/*
Plugin Name: My Custom Plugin
Description: Adds a custom functionality to my WordPress site.
Version: 1.0
Author: Your Name
*/

// Your custom functionality code goes here.
?>

3. Add Custom Functionality:

Within your main plugin file, add your custom functionality using WordPress hooks and functions. For instance, i am creating a custom plugin which will count numbers of visitors on each page and display it on that page:

// Function to increment and retrieve page visit count
function get_page_visit_count($post_id) {
    $count = get_post_meta($post_id, '_page_visit_count', true);
    $count = empty($count) ? 0 : intval($count);
    $count++;

    update_post_meta($post_id, '_page_visit_count', $count);

    return $count;
}

// Function to display visit count on the page
function display_page_visit_count() {
    $post_id = get_the_ID();
    $count = get_page_visit_count($post_id);

echo ' This page has been visited ' . $count . ' times. ';
}

// Hook the display function to the content
add_filter('the_content', 'display_page_visit_count');

4. Activate Your Plugin:

Go to the WordPress dashboard, navigate to "Plugins," and activate your custom plugin.

Here is complete tutorial for creating custom wordpress plugins: https://blog.hubspot.com/website/wordpress-plugin-development