1. Home
  2. Knowledge Base
  3. General
  4. How to add a code snippet to your site

How to add a code snippet to your site

From time to time, you might need to add a small amount of code to your site to modify a plugin’s behaviour or output. There are two recommended ways to do this:

Via your child theme’s functions.php file

If you are using a commercial theme, you should have created a child theme. This will allow you to add new code and modify the theme without the fear of your changes getting overwritten the next time the parent theme is updated.

You can create a child theme in a couple of different ways:

Whatever method you use, you should always add any code snippets to the functions.php file of your child theme, not the parent theme.

Use a snippets plugin

As an alternative to using your child theme’s functions.php file, you can install a plugin specifically designed to allow you to add snippets. The advantage of this is that you don’t need to edit theme files, you can add the snippets direct in your WordPress dashboard.

I recommend the free Code Snippets plugin for adding snippets to your site.

Was this article helpful?

Related Articles