Where to Put Custom Code for Your Website in WordPress

Written by Jean Galea
Written by Jean Galea

Table of Contents

Full disclosure: If you purchase through a link on our site, we may earn a commission. Here’s why you can trust us.

🚩 This article was written a while ago. If you find any outdated references, Please request an update →

AD

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.

This article was filed in our archives.
Article by
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

4 Responses

Share Your Thoughts

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

New discoveries, every week.
Join thousands of designers, developers, and builders that come to WP Mayor to find the best guides, tools, and services for their next website. One email, once a week.
WP Mayor Newsletter

Unlock higher conversions and a better user experience 🚀

Download our FREE 60/30/10 guide to web design.

By downloading this guide, you are opting in to our email list. You may unsubscribe any time.

What's missing?