Manage Code Snippets in WordPress with the Code Snippets Custom Post Type Plugin


Maintaining a library of code snippets can save you time when coding similar tasks in the future. Although there are countless sites online where you can host code snippets, it’s more convenient to have them at your fingertips when writing a blog that includes code.

Plugin developer Justin Sternberg recently released Code Snippets CPT, a plugin that allows you to manage and display code snippets in WordPress. This unique use of custom post types stores code snippets as their own individual posts, which can be pulled into content via a handy shortcode.

The plugin uses Google Code Prettify to add syntax highlighting to your snippets. When creating a new snippet, you simply select the language from the dropdown at the top of the post editor. Write a description, add your snippet, and click publish.


Code Snippets CPT also includes custom taxonomies for classifying your snippets. You can add both snippet categories and snippet tags, which will then allow for some unique ways of organizing and displaying your library of snippets.

When you want to display a snippet within a post or page, click on the “Add Snippet” button in the visual or text editor to launch the shortcode finder. You can select whether or not you want to display line numbers for the snippet that you are embedding.


Sternberg’s site is running the plugin, if you want to view a few live examples of snippets in posts.

Code Snippets CPT allows you to create a searchable archive of code snippets on your own site, without having to host snippets with a third party service. The advantage of hosting your own snippets is that you can keep your code library centralized and back it up as part of your WordPress site.

Having code snippets stored as custom post types is a step up from simply using a syntax highlighter plugin, because it gives you the flexibility to sort and display snippets using their own snippet-specific taxonomies. If you want to get your code library organized in 2015, check out the Code Snippets CPT plugin on


10 responses to “Manage Code Snippets in WordPress with the Code Snippets Custom Post Type Plugin”

      • Wow James, they are so similar in a lot of ways. I like some of the features you’ve incorporated like adding a new gistpen from your insert dialog as well as being able to change themes. Maybe we ought to consider joining efforts?

    • Did I get it wrong but isn’t that different kind of plugin. Code snippets plugin is for running code in your site, kind of like mini plugins.

      Code Snippets CPT is a plugin which you can use to display code snippets, not execute them.

  1. This looks great. I’ve been looking towards organizing and hosting my code in 2015, and this looks like a pretty nice way of doing it. Thanks Justin and Sarah for bringing it to our attention.

  2. Like Piet I’m a fan of Github for snippets. I use a private repo to store and sync Sublime Text snippets across my machines, private Gists to share with coworkers and public Gists to share/embed code in blogposts.


Subscribe Via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: