If you are a website developer, you might come across a client or situation where you need to create your own plugin, so here’s a quick tutorial on how to do this. First you need a code editor, we use Visual Studio Code.
Then you need to create the basic files. At first, we can just use 2 files, index.php and the name of your plugin, let’s say “my-first-plugin.php”.
We have the index.php file as a security measure so people can’t access the plugin code. Within this folder, add the code:
<?php die('you cannot be here'); ?>
/* * Plugin Name: YOUR PLUGIN NAME */
You may also need to put <?php at the top of the file to make sure your code edit knows you are coding in PHP. Then you have the basics of a WordPress plugins and you can add this to your WordPress site, unfortunalty it does not thing at this point. We should next add another layer of protection.
We should now add the following code under
if( !defined('ABSPATH') ) { die('You cannot be here'); }
Creating some simple functionality in your WordPress plugin
In order for our plugin to actually do something we need to add some more code, as an example we can hide the admin bar on the frontend. You may need to do this for a number of reasons. You can find this code online, we found it here https://themeisle.com/blog/code-snippets-for-wordpress/#gref. Just copy and paste the code under the absolute path code and save it. Then when you add your new plugin it will have some real useful functionality.
// Remove the admin bar from the front end add_filter( 'show_admin_bar', '__return_false' );