Add code to WordPress without editing functions.php

By Noiz / 19th October 2026 | 5 min

Tutorials often say "add this code to your theme's functions.php". To add code to WordPress safely, you put the PHP snippet in the free Code Snippets plugin instead. The plugin keeps your code apart from the theme, lets you switch each snippet on and off, and has a safe mode for when a snippet breaks the site. This guide is written for a Noiz client on any shared plan.

Before you start

  • A full backup. Take one: How to Generate a Full Backup in Plesk.
  • Know what the code does. Use snippets from the official WordPress documentation or a source you trust, and do not add code you cannot explain in a sentence. Never add code that asks for a password or sends data to another site.
  • An admin email address that reaches you. Check the one under Settings > General. If a snippet breaks the site, WordPress emails a recovery link there.
  • Plesk access. You can log in to Plesk, so that you can reach wp-config.php with Files if you need safe mode.

Last reviewed: 19 October 2026, against the current WordPress release. This guide is written for Noiz hosting and is kept current against WordPress. It complements, and does not replace, the official WordPress documentation linked below.

Official Documentation Reference

Why should you not add code to WordPress in functions.php?

Because your code disappears when the theme updates, and one typing error can take the site down.

  • Theme updates overwrite your code. The theme's functions.php is replaced whenever the theme updates, so your code disappears.
  • The Theme File Editor keeps no backup. One typing error there can take the whole site down, editor included.

"The editor does not make backup copies"

That is the WordPress documentation on the Theme File Editor.

A snippet plugin avoids both. The code lives in the database, survives theme updates, and can be switched off without touching a file.

Step 1: Install Code Snippets

Go to Plugins > Add New Plugin, search for Code Snippets, then install and activate it. A Snippets menu appears.

Step 2: How do you add a PHP snippet to WordPress?

You add it under Snippets > Add New, with a clear title and the narrowest scope that works.

  1. Go to Snippets > Add New.
  2. Enter a Title that says what it does, for example "Remove unused image size".
  3. Choose the Functions (PHP) type and paste the code. Leave out an opening <?php line if the tutorial includes one.
  4. Choose where it runs: Run everywhere, Only run in administration area, Only run on site front-end or Only run once. Pick the narrowest that works.
  5. Select Save and Activate.

Step 3: Test it

Open your site in a private browser window and check the home page, a post and anything the snippet should change. Then check the dashboard still works. To undo, go to Snippets, find the snippet and select Deactivate.

What do you do if the site breaks?

Switch every snippet off with safe mode. There are three ways in:

Way in What you need What it does
CODE_SNIPPETS_SAFE_MODE line in wp-config.php Plesk Files No snippet runs while safe mode is on, so the site comes back.
?snippets-safe-mode=1 added to a dashboard address Access to the dashboard as an administrator Switches snippets off, without editing a file.
The recovery link WordPress emails The admin email address A third way in.

To use the wp-config.php route:

  1. In Plesk, open Files and edit wp-config.php.
  2. Above the line that says to stop editing, add:
define( 'CODE_SNIPPETS_SAFE_MODE', true );
  1. Save. No snippet runs while safe mode is on, so the site comes back.
  2. Log in to WordPress, deactivate or fix the snippet, then remove the line from wp-config.php.

How do you lock the Theme File Editor?

Once your code lives in Code Snippets, nobody needs the built-in file editors. Turn them off by adding this line to wp-config.php with Files:

define( 'DISALLOW_FILE_EDIT', true );

For developers: a must-use plugin

If you keep code in files and version control, put it in a single PHP file in wp-content/mu-plugins. WordPress loads it automatically, and it cannot be switched off from the dashboard, which also means a mistake can only be fixed through the file. For styling changes and child themes, see How to Safely Edit Your WordPress Theme.

Troubleshooting

Symptom Cause and fix
"There has been a critical error on this website" The last snippet you activated has an error. Use safe mode.
The snippet does nothing Check its scope; a front-end snippet does not run in the dashboard, and the reverse.
The code worked in the theme but not as a snippet It may depend on the theme loading first. Ask the snippet's author, or ask us.

Read next:

Let Noiz Help

WordPress Care keeps WordPress and your plugins updated with a restore point first, so a plugin update that clashes with your snippet can be rolled back. Writing or changing custom code is quoted separately.