How to Add Custom Code Snippets in WordPress


Code snippets are similar to plugins – they both extend and expand the functionality of WordPress. Often WordPress tutorials involve adding custom code to your functions.php file.

At first this can look pretty easy but the slightest mistake or typo can break your website. Also if you have a lot of custom code, your functions.php file can become cluttered.

Normally, if you make a mistake when adding the custom code, it would immediately make your site inaccessible.

You would start seeing a syntax error or a 500 internal server error on your site. To fix this you’ll need to manually undo your code using an FTP client.

This is where the Code Snippets plugin comes in.

The neat part about this plugin is that it will automatically detect a syntax error in the code and immediately deactivate it.

This tutorial will show you an easy way to add custom code snippets in wordpress in an organized way with the help of this little plugin.

Let’s start by installing and activating Code Snippets on your website. After activation you will see a new menu label in your admin bar called “Snippets”.

Click on the snippets menu item and let’s get started.

Adding a new snippet

As always, make sure you have a WordPress backup plugin installed and properly configured. Better be safe than sorry.

To add a new snippet, click “Add New” at the top of the screen. At the next screen you need to give your code snippet a name. Think of a very distinct name so you know what the code snippet does just by looking at the name. Below are a few examples.

  • Comments – Remove reply button
  • Posts – Remove meta date and author links
  • System – Add local fonts

Now it’s time to start adding some code. Notice that you don’t have to add the php opening tag. Copy and paste your snippet into the code box.

After that you can assign tags and add an description. This can be anything to help you remember exactly what this snippet is for, where you got it from or how it is used.

About Bas Martens

Bas MartensLorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc imperdiet rhoncus arcu non aliquet. Sed tempor mauris a purus porttitor, ac convallis arcu venenatis. Donec lorem erat, ornare in augue at, pharetra cursus mauris.

Leave a Comment

Thank you for leaving a comment. All comments are moderated according to our comment policy. Keep comments in english please. We will never publish your email address.