Use Code Snippets with Dirigible
Code Snippets is a free plugin that stores PHP in the database so you can turn a piece of code off without editing theme files. Use it for small, reversible PHP. Put long-lived PHP in a child theme. Don't edit the parent Dirigible Studio theme.
Dirigible's hooks and filters are what most snippets should call.
When to use it
| You want | Use |
|---|---|
| CSS | Additional CSS or Section block CSS |
| A snippet you'll likely delete in a week | Code Snippets |
| PHP that should survive plugin experiments, or a copied template | A child theme |
Add a snippet
- Install and activate Code Snippets from Plugins β Add New.
- Go to Snippets β Add New.
- Give it a name you'll recognize in six months, such as "Banner under header".
- Paste the PHP. Skip the opening
<?phpif the editor already treats the box as PHP. - Choose where it runs: the front of the site, the WordPress admin, or both. For theme output, run it on the front of the site only.
- Save it inactive first. View the site. Then activate.
Test on staging when you can. One typo can take the site down.
Copy examples from Hooks and filters in the Dirigible theme. Don't paste PHP from a random blog post unless you understand what it does.
If the site goes white
WordPress Recovery Mode usually emails the administrator with a link to log in and deactivate the snippet.
If you can still reach the login page, add ?snippets-safe-mode=1 to the URL, for example https://yoursite.com/wp-admin/?snippets-safe-mode=1. That pauses every snippet for you (visitors still see the site as normal). Log in, deactivate the snippet that broke, then load a URL without that extra bit.
If you can't get in at all:
- Open your host's file manager or SFTP.
- Add this line to
wp-config.phpabove the line that says to stop editing:
define('CODE_SNIPPETS_SAFE_MODE', true);
- Reload the site. Log in, deactivate the snippet, then remove that line.
If you can't edit wp-config.php, rename the code-snippets folder inside wp-content/plugins (for example to code-snippets-off). That turns the whole plugin off. Rename it back after you can log in, then deactivate the bad snippet.
Things to know
- An inactive snippet does nothing. You can leave old ones in the list.
- Don't run two snippets that hook the same spot unless you mean both to fire.
- Code Snippets is a third-party plugin. Dirigible doesn't bundle it.