Where to Put Custom Code for Your Website in WordPress

  Introduction
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:.
WP Mayor’s work is supported by its audience. If you purchase through a link on our website, we may earn a commission. Here’s why you can trust us.
Table of contents

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.

Next step 

Jean Galea
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.
Jean Galea
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.
PeachPay for WooCommece

An all-in-one checkout and payment solution for WooCommerce . See your store's sales increase by 35%!

WP Engine Coupon
4 Months FREE with WP Engine

Get 4 months free on annual (or 20% off monthly) shared hosting plans from WP Engine, starting at just $20/mo.

Expand your toolset with expertly verified solutions delivered to your inbox every week.
Join thousands of designers, developers, and marketers who trust our experts to find and test the best tools for their WordPress sites.
By signing up to our newsletter, you agree to receive electronic communications from WP Mayor that may include advertisements.
Expand your toolset with expertly verified solutions delivered to your inbox every week.
Join thousands of designers, developers, and marketers who trust our experts to find and test the best tools for their WordPress sites.​
By signing up to our newsletter, you agree to receive electronic communications from WP Mayor that may include advertisements.

4 Responses

Leave a Reply

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

From web hosting to WooCommerce plugins and backup services, we have put together a collection of exclusive coupons and deals just for you.
WP Mayor_Icon_white
2022 Reader Survey