Where to Put Custom Code for Your Website in WordPress

If you purchase through a link on our site, we may earn a commission. Learn more.

Whenever you need to add custom code to your WordPress site, the typical recommendation is to put it in the theme's functions.php file. I don't like doing that as it's easy to forget to copy-paste that code to the new theme when it's time to a refresh. Moreover, if done in that manner, you don't have the ability to switch on or off certain functions. The solution for me has been the following plugins:.
Table of Contents
WP Engine High Performance Hosting
BionicWP Hosting

Whenever you need to add custom code to your WordPress site, the typical recommendation is to put it in the theme’s functions.php file.

I don’t like doing that as it’s easy to forget to copy-paste that code to the new theme when it’s time for a refresh.

Moreover, if done in that manner, you don’t have the ability to switch on or off certain functions.

The solution for me has been to use a simple plugin.

#1 Code Snippets

Code Snippets is an excellent plugin that lets you create snippets of code as functions that can be switched on or off at will, in the same way as you would with normal plugins.

Simply install the free plugin, create a snippet, paste your custom code, and save it.

Source: Code Snippets

You can then turn on or off any custom code at will without the risk of breaking your site.

#2 Custom Plugin

Alternatively, you can create your own custom plugin that stores your custom code.

In the past, we used to use Pluginception which let you create plugins from within the WordPress dashboard itself, but it hasn’t been updated in a while now.

It was useful when I just wanted to create one plugin to dump all the custom functionality into and have it protected whenever I change themes.

You can still do this by creating your own custom plugin, but if you’re not comfortable with code, go for option #1 and play it safe.

Jean Galea

Jean Galea is an investor, entrepreneur, and blogger. He is the founder of WP Mayor, the plugins WP RSS Aggregator and Spotlight, as well as the Mastermind.fm podcast. His personal blog can be found at jeangalea.com.

Discover more from our archives ↓

Popular articles ↓

4 Responses

Share Your Thoughts

Your email address will not be published. Required fields are marked *

Claim Your Free Website Tip 👇

Leave your name, email and website URL below to receive one actionable improvement tip tailored for your website within the next 24 hours.

"They identified areas for improvement that we had not previously considered." - Elliot

By providing your information, you'll also be subscribing to our weekly newsletter packed with exclusive content and insights. You can unsubscribe at any time with just one click.