How to Easily Add Custom Code in WordPress?


Do you want to add custom code easily in WordPress?

The addition of custom code is necessary while working in WordPress. Many tutorials also instruct us to add the code in your function.php file. Generally, function.php is a template that is found in the WordPress theme. It is like a plugin that automatically activates your current theme.

This is the shortest and quickest method. But, the only problem with adding code is small mistakes that break down the entire system and make it inaccessible. In addition to this, if you keep adding multiple code snippets in your site-specific plugin then it creates a problem managing the file.  

Without delay, let’s begin the actual answer to the question. In this method, we have mentioned two easy ways to add custom code.

1. Addition of Custom Code by Using a Plugin

The use of plugins is the easiest way to tackle the problem. This is a very simple and easy method with no risk at all. Code Snippets is the plugin that helps you to add codes without having fear of website collapse.

Follow the steps mentioned below:

  • Firstly, install and activate plugin Code Snippets.
Add custom code in WordPress.
  • Navigate to Snippets >> Add New in your WordPress admin bar.
Add custom code in WordPress.
  • Give a title to your code before adding them. Now all you need to do is copy and paste the code under the Code area.
Add custom code in WordPress.
  • Save and activate the code to check its performance. Also, it is saved in All snippets so, whenever you are required to edit the code. You can easily click on the “Edit” button and edit it.
Add custom code in WordPress.
  • For the sake of this article, we added code to add custom dashboard widgets from the, and here is the result. 
Add custom code in WordPress.

2. Addition of Custom Code by Creating a Custom Plugin 

This method is considered the best method to add custom code as it is unaffected even if the user changes or updates the theme. There are different ways to create a custom plugin. Here we are using a plugin to create a custom plugin.

Let’s start:

  • A submenu will appear in the plugin option-Create a New Plugin.
  • After clicking create a new menu a screen like below will appear where you need to fill with your information regarding the plugin.
  • Whenever you are done with the setting click on the Create a blank plugin and activate them. This will immediately direct you to the Editor page of the plugin
  • Hence, copy the same snippet of code used before in the Code Snippets plugin and you have successfully added code in WordPress.

Wrapping up

We hope this article was helpful for you. Undoubtedly, we have mentioned the two easiest ways to add a custom dashboard, you can follow the one which you feel is easy and simple.

Additionally, visit our tutorial “How to Edit WordPress Source Code Files?” for more information about source code.


Please enter your comment!
Please enter your name here