An easy, clean and simple way to run code snippets on your site.
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’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:
wp-content/plugins/folder of your WordPress installation
Network Activating Code Snippets through the Network Dashboard will enable a special interface for running snippets across the entire network.
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.
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 enable safe mode on a per-page basis by appending
&snippets-safe-mode=1 to end of the current page’s URL. While safe mode is active, all snippets will not execute, allowing you to login to your site and deactivate any snippets that are causing issues.
For example, to see the WordPress admin area in safe mode, you would change the URL from this:
… to this:
Or, for another example, if you were viewing a page on the front-end of your site, you could change a URL like this:
… to this:
This will only work if the current user is logged in as an administrator – other visitors will see your site as normal.
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,
Enterto find next,
Shift-Enterto find previous)
No, the snippets are stored in the WordPress database, independent of the theme and unaffected by WordPress upgrades.
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.
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.
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.
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.
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.
The best way to do this is to fork the repository on GitHub and send a pull request.
?snippets-safe-mode=trueto the URL
[code_snippets]shortcode for embedding snippet code in a post
get_snippets()function to retrieve individual snippets
<h1>tags instead of
?>functionality with a much more reliable regex method (#)
%character, props to nikan06 (#)
DISALLOW_FILE_EDITbeing set to true (#)