Yes, you read the title right – you can create WordPress plugin, and start using it in your website in just a few minutes.
It won’t be a huge do-it-all plugin, but plugins don’t always need to be complicated. In this tutorial I’ll show you how to add a simple plugin which will add custom code to WordPress website’s <head> section. Here’s exactly what you’ll learn:
- how to create WordPress plugin
- how to prepare plugin for WordPress
- how to upload your WordPress plugin via admin panel, and start using it
Remember, we have only a few minutes, so let’s get started!
Why you should create WordPress plugins instead of adding code to theme’s functions.php file
You probably know that you can always add small custom scripts to WordPress theme’s functions.php file. And that’s great. But this way has it’s shortcomings.
- If you switch WordPress theme in your website, all of the custom scripts will be deactivated with the theme.
- If you don’t use child themes in your WordPress site, one day you may forget about custom code you have in your theme’s functions.php, and all of the code will be lost if you update your theme.
- It’s much easier and faster to enable or disable plugin than look up and disable custom code in your theme’s functions.php file if you need it.
So the reason for creating your own WordPress plugins is clear I think.
How to create a simple WordPress plugin
Open any basic text editor (like Notepad), or any code editor (like VS Code, Notepad++). Basic text editor will work just fine now, and copy this code to it:
<?php
/**
* Plugin Name: My Custom Plugin
* Description: My first WordPress plugin built just in 5 minutes
* Version: 1.0
* Author: ImakeITwork
* Author URI: https://HowToSetup.website
* Text Domain: my-custom-plugin
*
* @author HowToSetup.website
* @copyright Copyright (c) 2022, HowToSetup.website
**/
function add_fathom_analytics() {
?>
<script src="https://cdn.usefathom.com/script.js" data-site="GPXXQRXX" defer></script>
<?php
}
add_action('wp_head', 'add_fathom_analytics');
The top section, which is between /**
and **/
symbols, describes your plugin. Replace plugin name with any name you want. Change Description, author – all this information is not critical, but will be visible after you upload the plugin to your site. Make sure, that your plugin name is the same as text domain, just replace all spaces and other special symbols with dashes as you see in the example – My Custom plugin became my-custom-plugin in the example.
Now it’s time to add your plugin functionality. In this example I’m adding Fathom Analytics code to website’s <head> section. First I create a function:
function some_function_name() {
// some code here
}
That function can be anything you want – custom css, javascript, php code, WordPress conditional logics etc.
Then I call that function using WordPress hook:
add_action('wp_head', 'some_function_name');
That’s all – code is ready. Save this file as my-custom-plugin.php (or any name you used in Text Domain, and save it as .php file).
How to prepare your custom WordPress plugin for uploading to your site
It may sound complicated, but it’s actually not complicated at all. If you want to upload your plugin to your website directly from WordPress admin panel, you need to compress it – save file as .zip .
Here’s how you do it in Windows 11:

Just click right mouse button on the plugin file you just created, and select Compress to ZIP file.
The same trick can be done in other operating systems, or you may use third party software like 7zip to compress your build WordPress plugin to Zip format.
Here’s the result:

That’s it – now your WordPress plugin is ready to use.
How to upload and install WordPress plugin via WordPress admin panel
Once your newly built WordPress plugin is ready open your website’s admin panel. Then go to Plugins >> Add New, and click on Upload Plugin button at the top of the page.

Click Choose File and select your WordPress plugin .zip file.

Click Install Now.

If you’ve done everything correctly, your plugin should be installed now. Hit Activate Plugin button to start using it.

That’s it – your custom WordPress plugin is working. You can view all the details you entered before in your website’s Plugins page.

Now if you’ll ever need to disable or remove your plugin from website, you’ll be able to do it in Plugins page.