How to Easily Add Custom Code in WordPress (without Breaking Your Site)

Often you can add personalized snippets of code to the functions.php file of your theme or in a site-specific plugin while reading WordPress tutorials. The problem is, that your website can be broken by even a minor error. We will show you in this Article an easy way to add custom code without breaking your website in WordPress.

The Custom Snippets Problem

In WordPress tutorials you often find snippets of code with instructions to put them in the functions.php file of your theme or a website-specific plugin. The problem is that your WordPress site can also be broken and made inaccessible even by a minor failure in your custom code snippet.

Secondly, you can make it difficult to manage the file if you add several codes snippets to a site-specific plug-in. We recently found an easy way for users to add and manage tailored code snippets in WordPress when they were looking for a solution.

Adding WordPress Custom Code Snippets

First, the Code Snippets plugin on your site must be installed and enabled. See our step-by-step guide on installing a WordPress plugin for more information. Only a new menu item called Snippet will be added to your WordPress Admin bar after activation.

If you click on it, a list of all the custom code snippets you saved on your website will appear. Your list will be empty as you have just installed the plugin. To add your first custom code in WordPress, go ahead and press the Add New button.

You can now access “Add New Snippet” on this page. 

You must first enter title for your custom snippet code. This could help you to identify the code. You can then copy your snippet code to the code box and paste it into.

We added custom code snippet in the screenshot above to remove our test siten version number from WordPress.

function wpb_remove_version() {
return '';
add_filter('the_generator', 'wpb_remove_version');
You can see text area below the code box to add description. You can add anything to understand what this code does, where it was found and why you add it to your web site.
You can also assign your snippet code tags. This helps you to sort your code snippets using themes and features. At the end, you can click on the button ‘ Save and enable.’ You can simply click the button “Save Changes” to save the code snippet and not activate it.
The scope of the code snippet may also be changed. You can only run this in the administration area of WordPress, at or anywhere on the front end of your site.
If you are unsure, then keep checked the default option to ‘run snippet all over.’ Once the snippet has been saved and activated, it will take effect immediately on your site.

Leave a Reply

Your email address will not be published. Required fields are marked *