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).

WpCodeBox is my favorite code snippets manager for WordPress. This is a premium plugin and if you’re interested, then grab WPCodeBox with a nice 20% discount here (SAVE 20% Coupon WPSH20).

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.

<span role="button" tabindex="0" data-code="

<?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

  • How to Duplicate a WordPress Page or Post with a single click?
  • How to Hide WordPress Admin Notifications
  • How to create custom fields in WordPress without a plugin?
  • How to Display Woocommerce Payment Methods Conditionally? (14 hacks)
  • How to Customize Woocommerce Stock Status? (17 hacks)
  • How to Add Custom Endpoints in WooCommerce?
  • How to add and clone user roles in WordPress?
  • How to restore WordPress classic widgets?
  • How to Add Custom Admin Menu Items in WordPress?
  • How to Remove WordPress Admin Menu Items for Specific User Roles?
  • How to Clean & Remove Divi Shortcodes When Changing Your Theme?
  • How to Create Custom WordPress Admin Dashboard for your customers?

Leave a Comment

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

Scroll to Top