Docs

How To Add a Custom Code Snippet To Your WordPress Site?

Updated on

Adding custom code snippets to your WordPress site can help you extend functionality without needing a full plugin; however, how you add the code matters for both safety and maintainability.

Note: You can add code to your child theme’s functions.php file, but it’s risky; errors can break your site, and changes may be lost or hard to manage.

Experts recommend using a WordPress plugin because these are safe and won’t break your site. 

To use this plugin to add a custom code snippet to your site, follow these steps: 

Step 1: Install and activate the WPCode plugin 

At FunnelKit, we recommend using the WPCode plugin (formerly Insert Headers and Footers).

You can easily install and activate the plugin from the WordPress dashboard. Go to Plugins ⇒ Add Plugin, search for WPCode, then install and activate the plugin. 

WPCode plugin install and activate screen in the WordPress dashboard

Step 2: Add the code snippet

Now go to Code Snippets ⇒ + Add Snippet. Then hit the option +Add Custom Snippet. 

Add custom code option in the WPCode plugin

Next, choose the code type (PHP, JavaScript, HTML, CSS, etc.). To add custom functionality to FunnelKit plugins, you’ll typically need to select PHP.

Selecting the PHP snippet type in WPCode

After that, name the custom code snippet and paste the custom code in the Code Preview section. 

Name custom snippet and add code

Step 3: Activate and save the snippet 

After adding the custom code, make sure to activate the snippet and hit “Save Snippet.”

Activate and save options for a snippet in WPCode

And that’s it. You can follow the same process to add any custom code to your site.