How to create your own custom code snippets plugin for WordPress?

There are a bunch of fancy code snippets managers for WordPress. For example, Code snippets is one of the most popular plugins that I also sometimes use.

Add a snippet shown here below to your child theme’s functions.php file or better yet, use a snippet manager like Code Snippets or WpCodeBox (my favorite).

In this post I’ll show you how to create your own custom code snippets plugin for WordPress. See the screenshots below:

How to create your own custom code snippets plugin for WordPress?
This is a simple custom code snippets plugin for WordPress I created

How to create your own custom code snippets plugin for WordPress?
These are the snippets I added to my code snippets plugin for WordPress

Video: How to create your own custom code snippets plugin for WordPress?

Take a look at the short video down below here, and it will give a good overview of how to make it work.

Tutorial: How to create your own custom code snippets plugin for WordPress?

Step 1: Create a new folder in your computer and name it snippets

Step 2: Open this folder and create a new file called snippets.php (pay attention, that the file extension must be .php)

Step 3: Open this file and paste this code snippet inside this file and save.

<?php
	/*
    Plugin name: My custom snippets
    Description: These are my snippets which usually are inserted inside functions.php file
    Version: 1.0
    Author: WP Simple Hacks
    Author URI: https://wpsimplehacks.com
    License:
    License URI:
	 */
	
	if ( ! defined( 'ABSPATH' ) ) {
		exit;
	}

	// Add new menu called "My snippets" under Plugins menu

	add_action( 'admin_menu' , 'admin_menu_new_items' );
	function admin_menu_new_items() {
	global $submenu;
	$submenu['plugins.php'][500] = array( 'My snippets', 'manage_options' , '/wp-admin/plugin-editor.php?file=snippets%2Fsnippets.php' );
	}

You can add your own plugin name, description, author etc. inside this file. Pay attention though, that if your folder name is something else than “snippets” or your file name is something else than “snippets.php” then you would need to change this part of the code accordingly (line 21) .

snippets%2Fsnippets.php

Step 4: Go back to the folder view and compress your snippets folder. Now you should have a compressed file snippets.zip

Step 5: Install your new plugin. Go to Plugins >> Add new >> Upload plugin and activate it. Now you’ll see a new submenu called “My snippets” (it’s under Plugins menu)

Step 6: Open My snippets menu and add your own snippets and save.

If for some reason it doesn’t work out for you, then take a look at the video above.

Related WordPress hacks

Here are some of my favorite WordPress tools

Thanks for reading this article! I hope it's been useful as you work on your own websites and e-commerce sites. I wanted to share some tools I use as a WordPress developer, and I think you'll find them helpful too.

Just so you know, these are affiliate links. If you decide to use any of them, I'll earn a commission. This helps me create tutorials and YouTube videos. But honestly, I genuinely use and recommend these tools to my friends and family as well. Your support keeps me creating content that benefits everyone.

Themes: Over the past few years, I've consistently relied on two primary themes for all sorts of projects: the Blocksy theme and the Kadence Theme. If you explore this website and my YouTube channel, you'll come across numerous tutorials that delve into these themes. If you're interested in obtaining a 10% discount for both of these themes, then:

Code Snippets Manager: WPCodeBox allows you to add code snippets to your site. Not only that, but it also provides you with the capability to construct and oversee your WordPress Code Snippets library right in the cloud. You can grab it with the 20% discount here (SAVE 20% Coupon: WPSH20).

Contact forms: There are hundreds of contact forms out there but Fluent Forms is the one I like the most. If you need a 20% discount then use this link (save 20% coupon is WPSH20).

Gutenberg add-ons: If I need a good Gutenberg blocks add-on then Kadence Blocks is the one I have used the most. You’ll get a 10% discount with the coupon SIMPLEHACKS here.

Website migration: While building a website you probably need a good plugin that can help you with the migration, backups, restoration, and staging sites. Well, WpVivid is the one I have used for the last couple of years. If you use this link along with the WPSH20 coupon you’ll get a 20% discount.

Woocommerce extensions: There are a bunch of Woocommerce extensions that I like but the one that stands out is Advanced Dynamic Pricing. Once again, you’ll get a 20% discount if you use this link here (save 20% coupon is WPSH20)

Web Hosting: If you would like to have a really fast and easy-to-use managed cloud hosting, then I recommend Verpex Hosting (see my review here). By the way, this site is hosted in Verpex.)

To see all my most up-to-date recommendations, check out this resource that I made for you!

Do you want to thank me and buy me a beer?

Every donation is entirely welcome but NEVER required. Enjoy my work for free but if you would like to thank me and buy me a beer or two then you can use this form here below.

Donation Form (#2)

Janek T.
Janek T.

Improve this text: {CLIPBOARD}

- I have been passionate about Wordpress since 2011, creating websites and sharing valuable tips on using Wordpress and Woocommerce on my site.
- Be the first to receive notifications about new tutorials by subscribing to my Youtube channel .
- Follow me on Twitter here

Articles: 105