Easy way to add custom PHP code on your WordPress site

A short instruction on how to Use Code Snippets plugin to add custom PHP code snippets on your WordPress site without files modifications.

We highly not recommend modifying WordPress themes and plugins!

A next software update will wipe out all the modifications from the code, so you will be forced to restore them each time.

The most obvious way is to create a child theme or custom plugin for all your code mods and snippets. But it requires you have some knowledge in coding. And if you are not skilled enough or don’t want to hire a specialist for a 1-minute job, so try following.

There is an easy way to add some code on your site though the admin dashboard – using the Code Snippets plugin.

It allows you to create separated PHP code blocks (snippets) like you create new posts. You can disable or enable each snippet whenever it needs.

So, whenever you need to create a new custom PHP code snippet, you can do the following steps:

1. Open Snippets list and Add New one.

Code Snippets list
Code Snippets list

2. Add the snippet Name, description and put the custom PHP code.

Add custom PHP code on the Code Snippets form
Code Snippets form

3. Save changes and activate.

HINT: Always try to set option “Only run on front-end” if it is possible. Because if the code contains errors they might block your site back-end and you will not be able to disable this snippet.

If a terrible thing nonetheless happened!

If you made a fatal error in PHP code and the snippet were activated in the WordPress dashboard. You are in trouble, but not so bad. You still able to deactivate Code Snippets plugin in the safe mode.

You can enable safe mode on a per-page basis by appending &snippets-safe-mode=1 to end of the current page’s URL. This will allow you to login to your site and deactivate any snippets that are causing issues.

For example, you would change WordPress admin area URL from this:


… to this: