How to create a basic WordPress plugin? Step By Step


Table Of Contents

WordPress plugins are add-ons that can be installed on a WordPress website to extend its functionality and capabilities. They can be used to add new features, modify existing ones, or integrate with other software and services.

To create a basic WordPress plugin, follow these steps:

  1. Open a text editor and create a new file called “my-plugin.php”.
  2. At the top of the file, add the following lines of code to define a new plugin and provide some information about it:
Plugin Name: My Plugin
Description: This is my first WordPress plugin.
Version: 1.0
Author: Your Name
  1. Next, add a function that will be called when the plugin is activated. This function can be used to perform any setup tasks that are required for your plugin to work properly. For example:
function my_plugin_activate() {
    // Perform setup tasks here
register_activation_hook( __FILE__, 'my_plugin_activate' );
  1. Now, add a function that will be called when the plugin is deactivated. This function can be used to perform any cleanup tasks that are required, such as removing any custom database tables or options that were created by your plugin. For example:
function my_plugin_deactivate() {
    // Perform cleanup tasks here
register_deactivation_hook( __FILE__, 'my_plugin_deactivate' );
  1. Finally, add the code that will make your plugin do something useful. This could be anything from modifying the way WordPress works to adding new features or functionality to your site. For example, you could add a shortcode that allows users to easily embed a YouTube video in a post or page:
function my_plugin_shortcode( $atts ) {
    // Extract shortcode attributes
    extract( shortcode_atts(
            'id' => '',
    ) );

    // Return YouTube embed code
    return '<iframe width="400" height="300" src="" title="WordPress Plugin Development: Gutenberg Blocks, React & More" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
add_shortcode( 'youtube', 'my_plugin_shortcode' );
  1. Save the file and upload it to the wp-content/plugins directory on your WordPress site.
  2. In the WordPress admin dashboard, go to Plugins and activate your plugin.
  3. You can now use your plugin by using the shortcode you defined in the code. For example, to embed a YouTube video with the ID 12345, you would use the following shortcode in a post or page: [youtube id="12345"].

Note: You can find more detailed information about creating WordPress plugins and using WordPress hooks and filters in the WordPress Codex (

Are you looking for a reliable and experienced WordPress expert?

Look no further! Our team of experts has years of experience in creating and managing WordPress websites. From custom theme design to plugin integration, we have the skills and knowledge to take your website to the next level. Contact us today and let us help you bring your vision to life!
Leave a Reply

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

    Copyright 2022 | All Rights Reserved.