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
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.
Because your code disappears when the theme updates, and one typing error can take the site down.
functions.php is replaced whenever the theme updates, so your code disappears."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.
Go to Plugins > Add New Plugin, search for Code Snippets, then install and activate it. A Snippets menu appears.
You add it under Snippets > Add New, with a clear title and the narrowest scope that works.
<?php line if the tutorial includes one.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.
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:
wp-config.php.define( 'CODE_SNIPPETS_SAFE_MODE', true );
wp-config.php.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 );
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.
| 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:
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.