This page may contain affiliate links. Please read my disclaimer for more information.

Adding Code Snippets to Your WordPress Site

We recommend when you need to add code snippets to your site you either add the code to your themes functions.php file or you use a functionality plugin. Below I will show you how to use both of these methods.

First Back Up Your Site!

Before moving forward, please perform a full website backup, just in case! We recommend using BlogVault

Functionality Plugin

This is the recommended solution. When using this method, you reduce the risk of breaking your site and causing issues that you can not undo without help.

You will need to install a plugin, we recommend the Code Snippets plugin shown below.

Once installed and activated, follow the steps below.

  1. Click WPCodeBox
  2. Click New Snippet
  3. Enter a Title
  4. Select Type of Code
  5. Past in your code
  6. Make any modifications
  7. Click Save
  8. Click the Toggle to Enable

When NOT to use this method

I can’t really think of a reason not to use this method. It is the most ideal solution. Not only is it easy, but if you ever enter bad code, instead of crashing your site, it will cancel your changes and display an error like this:

Functions.php File Method

This will require editing one of your core theme files, functions.php.

You can do this from within your WP Admin or through an FTP client.

From within the WP Admin you can edit your theme files directly (recommended) or you can use a plugin like File Manager to to access and edit your theme files.

WP Admin Theme Editor

  1. Go to Appearance
  2. Click Theme Editor
  3. Click Theme Functions (Top Right)
  4. Scroll down to the end of the code in the editor
  5. Past in your code

Important: If your functions file has a php closing tag, ?>, be sure that you place your code above this tag.

File Manager Plugin

If you decide to use this option, we recommend that you deactivate and delete this plugin once you’re done using it. Install this plugin, WP File Manager.

Once activated follow the steps below.

  1. Click on File Manager
  2. Double Click wp-content
  3. Double Click themes
  4. Double Click your theme folder
  5. Right click on functions.php
  6. Select Code Editor
  7. Scroll down to the bottom and past in your code
  8. Click Save & Close

Important: If your functions file has a php closing tag, ?>, be sure that you place your code above this tag.

FTP Client

This step requires getting direct access to the files on your server. You will have to create an FTP user then use a client like FileZilla to connect to your the server. You will also need a text editor to modify the functions.php file.

If you are unfamiliar with FTP, I would recommend using one of the methods above, or using a service like out One Time Fix to do this for you!

This video will teach you about accessing files via FTP and how to upload files through FTP.

When NOT to use this method

You should never edit your themes functions.php file if you are not using a Child Theme. If you edit your themes core files and then receive an update for that theme, your changes will be overwritten.

With the use of a child theme, you will not need to worry about core theme updates.

You should also avoid modifying your themes functions.php file if you are not comfortable with the risk of breaking your site.

The Wrap Up

It is completely understandable if you don’t want to make any of these modifications yourself! Trust me, there have been plenty of times I entered some bad code and crashed my site.

You can always use a staging or development environment, like WP Engine provides, to clone your site, make your changes, test your changes, then clone your changes to production without your visitors even knowing.

Leave a Comment

Join The Mantis Report

Get weekly WordPress news, resources, tutorials, and other tips from our experts.

Name*
This field is for validation purposes and should be left unchanged.
Skip to content