How to Add Custom Code Snippets in WordPress

Introduction

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.

How to Add Custom Code Snippets in WordPress

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.

Previous

How to Add Previous and Next Post Links with Thumbnails in WordPress

How to Load jQuery from Google’s CDN

Next

Leave a Comment

0 Shares
Share
Tweet
Share
Email
Secured By miniOrange