---
title: "How To Add Custom Snippets with Code Snippets"
source: "https://docs.nexcess.com/software/kadence/blocks/add-custom-filter-or-function-with-code-snippets/"
description: "The easiest way to add custom PHP or JavaScript functions to your site is by using a code snippets plugin. Compared to a child theme, it offers better organizat…"
vertical: "Software"
area: "Kadence Blocks"
date: "2020-11-16"
last_modified: "2026-07-02"
---

# How To Add Custom Snippets with Code Snippets

The easiest way to add custom PHP or JavaScript functions to your site is by using a code snippets plugin. Compared to a child theme, it offers better organization for your custom code, allowing you to enable or disable snippets with a single click, export and import them, and more. Using a plugin also includes safeguards to help prevent site-breaking errors, and if something does go wrong, there are simple ways to regain access and fix your code.

Install the Code Snippets Plugin

You can install the [Code Snippets plugin](https://wordpress.org/plugins/code-snippets/) by going to your WordPress Dashboard and clicking Plugins → Add new. Then search for *code snippets*.

![Installing Code Snippets via WordPress Admin](https://docs.nexcess.com/wp-content/uploads/2026/06/Screenshot-2025-09-26-at-1.03.20-PM-scaled-1.png)Once installed and activated, you can navigate to **Snippets** in your admin menu. Code Snippets provides several example snippets that you can use and/or edit to see how things work.

![Code Snippets Dashboard](https://docs.nexcess.com/wp-content/uploads/2026/06/Screenshot-2025-09-26-at-1.10.57-PM-scaled-1.png)If you want to learn more about the plugin and it’s available settings check out the [WordPress plugin page](https://wordpress.org/plugins/code-snippets/).

Adding a PHP Snippet

To add a PHP snippet, click **Add New** in the Snippets menu and then add in your code into the code area. The plugin defaults to **PHP** and you can also set the Location.

**Location**:

- Run Everywhere *(default)*
- Only run in administration area
- Only run on site front-end
- Only run once

![Code Snippets - adding a new PHP snippet](https://docs.nexcess.com/wp-content/uploads/2026/06/Screenshot-2025-09-26-at-1.14.55-PM-scaled-1.png)Once you’ve added your function and set the Location, click **Save and Activate**. If your snippet contains any syntax errors, **it will not activate**.

Adding a JavaScript or HTML Snippet

To add a JavaScript or HTML code snippet you can click **Add New** in the Snippets menu and, before adding your code, change the type to **HTML** and set the Location.

**Location:**

- Where inserted in editor *(default)*
- In site <head> section
- In site footer (end of <body>)

![Code Snippets - adding an HTML snippet](https://docs.nexcess.com/wp-content/uploads/2026/06/Screenshot-2025-09-26-at-12.54.29-PM-scaled-1.png)Optionally add a description and tag and then **Save and Activate** your snippet.

Other Code Snippet Plugins

Here are a few good alternatives for adding snippets to your site:

- [WPCode](https://wordpress.org/plugins/insert-headers-and-footers/)
- [FluentSnippets](https://wordpress.org/plugins/easy-code-manager/)
