How to add custom code in WordPress without Plugins

Learn how to add custom code in WordPress without installing additional plugins. This article explains all common methods of adding custom code and where to place it depending on the requirements.

Whether you need to insert PHP, JavaScript, or CSS, follow this guide and you’ll see the best methods of adding custom code without installing custom code snippet plugins.


One of the key features of WordPress that placed it in front of other blogging and CMS platforms, is the ease of customization.

With over 2500+ hooks, we can customize the way WordPress works in almost any aspect.

Sometimes we just need to add some simple CSS code or jQuery snippet and sometimes the code might be more complex. We illustrate here the most known methods of adding custom code.

The easy way of adding custom CSS in WordPress – No Plugins

If you just trying to add custom CSS code you can do it right from WP Admin Dashboard.

Just access WP admin > Appearance > Customize. Once the customizer options are loaded, access the Additional CSS from the menu on the left side and paste your code inside.

Many classic WP themes are offering a Custom CSS option inside the Theme Options panel You can use it to paste the Custom CSS code as well.

You can also use Chile theme to add custom code, you will need to switch your website theme to it’s child theme. Then you can paste the CSS code inside the style.css file of the child theme.

The reason why we need a child theme is to apply customization without worrying about the main theme updates. As all updates are overwriting the files, thus any customization on the main theme files will be lost. The child theme takes care of that.

Important: If you plan to override some CSS style on the front end that is coming from the theme or some plugin, make sure that you add the !important; at the end of your CSS statement.

For example:

.yourclass {
     color:#FFCCEE !important;

Adding JavaScript code in WordPress without Plugins

If you want to add some JS code or jQuery snippet in WordPress, there are a couple of methods that allow you to do so.

There is no built-in option for inserting JS code, but we can add it using these methods.

The first method is to add the JS code inside the file located in the child theme directory. Then we need to enqueue the JS file inside the child theme functions.php file.

For example, we can make our own custom.js file and paste the JS code inside. Then save this file to the child theme folder.

Prior to applying modifications to PHP files, it’s advisable to make a full website backup.

Open the functions.php file for editing and add this code:

function wrd_my_custom_scripts() {

	wp_register_script('my_js_script', get_stylesheet_directory_uri() . 'js/my_script.js', array('jquery'),'1.1', false);

add_action( 'wp_enqueue_scripts', 'wrd_my_custom_scripts' );  

Now, please make sure to replace the path with your real JS file location.

Please, see the official WordPress Codes on WP Enqueue function.

You can also insert the JS code using wp_head action. See this example:

function wrd_print_js() {
	<script type="text/javascript">
	// your javscript code goes here
	// ...
add_action('wp_head', ' wrd_print_js');

This solution will print your JS code inside the <head> element of all pages. You can also set it to the footer area by replacing the wp_head with wp_footer inside the add_action syntax.

Adding custom PHP code in WordPress without Plugins

The PHP code can be added in the same way as the JS code, by files. You will just need to include the files inside your Child theme functions.php.

Here is an example of referencing our custom PHP code located inside /inc/myfile.php.

include_once( get_stylesheet_directory() .'/inc/myfile.php');

We will use this syntax since we are using a Child theme for applying modification. You can use require_once for calling PHP files with full path.


These should be the easiest method of adding custom code in WordPress without installing any additional Code snippet Plugins.

Feel free to share any other methods you might consider useful for our readers or feel free to ask for help in the comments below.

Share this post if you like it.
Worda Team
Worda Team

Our team of WordPress professionals will help you stay on the latest WP topics, resolve any problem or issue with the WordPress website or provide useful advice. Feel free to get in touch with us. :)

Leave a Reply

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