Code Snippets is an easy, clean and simple way to run PHP code snippets on your site. It removes the need to add custom snippets to your theme theme’s
A snippet is a small chunk of PHP code that you can use to extend the functionality of a WordPress-powered website; essentially a mini-plugin with less load on your site.
Most snippet-hosting sites tell you to add snippet code to your active theme’s
functions.php file, which can get rather long and messy after a while.
Code Snippets changes that by providing a GUI interface for adding snippets and actually running them on your site just as if they were in your theme’s
Code Snippets provides graphical interface, similar to the Plugins menu, for managing snippets. Snippets can can be activated and deactivated, just like plugins. The snippet editor includes fields for a name, a visual editor-enabled description, tags to allow you to categorize snippets, and a full-featured code editor. Snippets can be exported for transfer to another side, either in JSON for later importing by the Code Snippets plugin, or in PHP for creating your own plugin or theme.
If you like this plugin, or it is useful to you in some way, please consider reviewing it on WordPress.org.
If you’d like to contribute to the plugin’s code or translate it into another language, you can fork the plugin on GitHub.
Code Snippets can be used in these different languages thanks to the following translators:
Danish – Finn Sommer Jensen
French – momo-fr and Shea Bunge
Belarusian – Hrank.com
Brazilian Portuguese – Bruno Borges
French (Canada) – Dominic Desbiens
Indonesian – Jordan Silaen from ChameleonJohn.com
German – Mario Siegmann, Joerg Knoerchen, and David Decker
Dutch – Sander Spies
Slovak – Ján Fajčák
Russian – Alexander Samsonov
Chinese – Jincheng Shan
Serbo-Croatian – Borisa Djuraskovic from Web Hosting Hub
Japanese – mt8
Log into your WordPress admin
Click Add New
Search for Code Snippets
Click Install Now under “Code Snippets”
Activate the plugin
Click to Download the plugin
Extract the contents of the zip file
Upload the contents of the zip file to the
wp-content/plugins/ folder of your WordPress installation
Activate the Code Snippets plugin from ‘Plugins’ page.
Network Activating Code Snippets through the Network Dashboard will enable a special interface for running snippets across the entire network.
How can I insert my snippet into the post text editor?
Snippets that you add to this plugin are not meant to be inserted into the text editor. Instead, they are run on your site just as if they were added to your functions.php file.
Help! I just activated a snippet, and my whole site broke!
You can try activating ‘safe mode’. All snippets will not execute while safe mode is active, allowing you to access your site and deactivate the snippet that is causing the error. To activate safe mode, add the following line to your wp-config.php file, just before the line that reads
/* That's all, stop editing! Happy blogging. */:
To turn safe mode off, either comment out this line or delete it.
You can also activate safe mode on a per-page basis by appending
?snippets-safe-mode=true to the URL – this will only work if the current user is logged in as an administrator.
Can I search and replace text inside the code editor?
The code editor supports several search and replace commands, accessible through keyboard shortcuts:
Cmd-F – Begin searching
Cmd-G – Find the next instance of the search term
Shift-Cmd-G – Find the previous instance of the search term
Cmd-Option-F – Replace text
Shift-Cmd-Option-F – Replace all instances of text
Alt-F – Persistent search (dialog remains open,
Enter to find next,
Shift-Enter to find previous)
Will I lose my snippets if I change the theme or upgrade WordPress?
No, the snippets are stored in the WordPress database, independent of the theme and unaffected by WordPress upgrades.
Can the plugin be completely uninstalled?
If you enable the ‘Complete Uninstall’ option on the plugin settings page, Code Snippets will clean up all of its data when deleted through the WordPress ‘Plugins’ menu. This includes all of the stored snippets. If you would like to preserve the snippets, ensure they are exported first.
Can I copy any snippets I have created to another WordPress site?
Yes! You can individually export a single snippet using the link below the snippet name on the ‘Manage Snippets’ page or bulk export multiple snippets using the ‘Bulk Actions’ feature. Snippets can later be imported using the ‘Import Snippets’ page by uploading the export file.
Can I export my snippets to PHP for a site where I’m not using the Code Snippets plugin?
Yes. Click the checkboxes next to the snippets you want to export, and then choose Export to PHP from the Bulk Actions menu and click Apply. The generated PHP file will contain the exported snippets’ code, as well as their name and description in comments.
Can I run network-wide snippets on a multisite installation?
You can run snippets across an entire multisite network by Network Activating Code Snippets through the Network Dashboard. You can also activate Code Snippets just on the main site, and then individually on other sites of your choice.
Where are the snippets stored in my WordPress database?
Snippets are stored in the
wp_snippets table in the WordPress database. The table name may differ depending on what your table prefix is set to.
I need help with Code Snippets / I have an idea for a new feature for Code Snippets
I want to contribute to and help develop the Code Snippets plugin!
That’s fantastic! Fork the repository on GitHub and send me a pull request.