Skip to content

Quickly Add Code Snippets in WordPress

Debates have raged for ages—and still rage—about how to think about code on a WordPress site. Some people are fast-and-loose types who just want it working quickly as possible. For people in a hurry, the Code Snippets plugin is a quick and effective way to build and manage small quick “WordPress hacks.” While I still think file-system access is a better idea for writing WordPress PHP, I can’t deny the quickness of this (or any) PHP code snippets plugin.

In general, a WordPress snippet will just be a bit of code you’ll get from something like a theme or plugin seller to make their code work more how you’d like. I think it quickly gets unwieldy and confusing when you use too many of these in a plugin like the one we’re covering. But with this plugin’s quick-and-easy error-recover system, I can say I found it hard to really “break” a site. Without further ado…

How to Manage WordPress PHP Code Snippets, the video

Add a PHP Code Snippet to Your WordPress Site

  1. Install the plugin. To install the Code Snippets plugin, go to the “Plugins > Add New” page in your WordPress site. In the search box, you’ll enter the plugin name “Code Snippets.” “Install” the plugin, and then “Activate” it.
  2. Go to the page to add a snippet. If you’ve successfully got the “Code Snippets” plugin running, you’ll now have a new menu item in the your left admin sidebar. You’ll see “Snippets” (with a scissors logo) under the typical place you’ll have your “Plugins” menu item. To add a new snippet, select “Add New” in the snippet menu.
  3. Add the snippet. On the “Add New Snippet” screen, you’ll be able to paste your little PHP snippet. It goes in the big box labelled “Code.” Above that you’ll have space to give the code block a “title” or “name” so that you’ll be able to find it later in the rest of the interface for the plugin. To get your PHP snippet running, you’ll click on the “Save Changes and Activate” plugin in the bottom. (Worth knowing: you can save snippets that themselves aren’t running. That’s what the “Save Changes” button would do for us.)

That’s it. One of the things I like about the Code Snippets plugin is that if you create a fatal PHP error (not as bad as “fatal” implies, but still a problem), you’ll be able to undo that change by simply clicking the “Back” button in your browser. (I show this off in the video 🤓)

Yay! 🎉 You made it to the end of the article!
David Hayes

Inline Feedbacks
View all comments

Or start the conversation in our Facebook group for WordPress professionals. Find answers, share tips, and get help from other WordPress experts. Join now (it’s free)!

Would love your thoughts, please comment.x

Most Searched Articles

Best JavaScript Libraries and Frameworks: Try These 14 in 2024

In this post, we look at the best JavaScript libraries and frameworks to try out this year. Why? Well, with JavaScript being available in every web browser, this makes it the most accessible programming language of ...

20 Best Free WordPress Themes for 2024 (Responsive, Mobile-Ready, Beautiful)

If you're looking for only the best free WordPress themes in the market for this year, then you're in the right place. We have more than enough such themes for you right ...

12 Best WordPress Hosting Providers of 2024 Compared and Tested

Looking for the best WordPress hosting that you can actually afford? We did the testing for you. Here are 10+ best hosts on the market ...

Handpicked Articles

How to Make a WordPress Website: Ultimate Guide for All Users – Beginners, Intermediate, Advanced

Many people wonder how to make a WordPress website. They’ve heard about WordPress, its incredible popularity, excellent features and designs, and now they want to join the pack and build a WordPress website of their own. So, where does one get ...

How to Start an Ecommerce Business: Ultimate Guide for 2024

Is this going to be the year you learn how to start an eCommerce business from scratch? You’re certainly in the right place! This guide will give you a roadmap to getting from 0 to a fully functional eCommerce business. ...