Custom Code Snippet increases your site functionality. When you create a website, you may have to add some code in it. But if you make a mistake in adding your custom code snippet, it will break your site with syntax error or 500 internal server error.
Don’t worry, In this handy guide, I will tell you a safe and easy way how to properly add custom code to your WordPress site.
WordPress code snippets are found everywhere on the web. By adding these code snippets, you can increase and modify the behaviour of your website.
So, let’s get started…
Brief Descriptions of The Content
How to Safely Add Code Snippets in Your WordPress Site
First, install and activate Code Snippets plugin on your WordPress site.
Code Snippets is an easy, clean and simple way to add code snippets to your site. It provides a user-friendly interface. You can activate and deactivate your added snippets just like plugins. Also, includes fields for a name, description, tags to categorize snippets.
After activation, this will add snippets menu items to your site. To add new code snippets click on Snippets >> Add New.
Now enter a title for your custom code snippet. It can be anything that will help you identify the code later. After that, you can paste your code snippet into the code box.
Here, I’m adding custom code snippets to remove Proudly Powered By WordPress link from the footer. You can see screenshot below.
After adding, you can add a description and tag for your code snippets to understand what this code does, where you found it, and why you are adding it to your website.
Also, you can sort your CSS code snippets based on functionality.
Once done, click on the Save Changes and Activate button. This will immediately take effect on your site. But if you want to save the code snippet only and do not want to activate, click on the Save Changes button only.
What NOT to Do When Adding Custom Code to Your WordPress Site
- Do not add code snippets directly to your function.php file – Functions.php file contains very important information. If you do something wrong while editing it, then it can make your site unusable as a syntax error or 500 internal server error.
- Do not add code directly to your parent theme or plugin files – Do not modify parent theme or any plugin files directly. After the theme or plugin update, you will have to make modifications again.
What to Do When Adding Custom Code to Your WordPress Site
- Backup your WordPress website – Before modifying anything in your website, backup it first. So if you have any problem, you can restore the working version again. Here is a guide – How to Backup WordPress site completely using UpdraftPlus plugin
- Create a child theme – A child theme is used to make changes or add custom code to a WordPress website without touching parent theme files. If you want to insert code snippets without a plugin in your site, then child theme is the best method. Always use a child theme, when you making major edits.
Wrapping It Up
In this handy guide, I showed you how to add custom code snippets to the WordPress site using the Code Snippets plugin.
Code Snippets is an easy and best way to add code snippets to your WordPress site. It provides a user-friendly interface to manage your custom code snippets.
You can save your code snippet without activating it. Apart from this, it allows you to deactivate the code snippet at any time.
The best part is that, if you migrate your WordPress websites to another server, you can easily import all the code snippets through the Import feature. Just click on the snippet >> Import.
If you use any other code snippet editor on your site, share your experience.
What did you think of today’s post? Let me know by leaving a comment below.
Find this article helpful? Don’t forget to share!