Where to put your code in
the WordPress functions.php file

You can paste your code almost anywhere in your functions.php file. Here’s a quick example underneath.

If you’d like a more detailed answer, read on below.

Functions.php

As you’re beginning your WordPress journey and entering a coding universe, it can get confusing. In order to get a better grasp on it, let’s take a look at the WordPress functions.php file.

In this post, we’re going to assume you found a code which is supposed to go into your WordPress functions.php file.

To understand where a code goes, you need to know where it stops and ends.

Lets take a quick example of some typical WordPress php code. We’ve taken a very short code snippet from a typical functions.php file. It looks something like this:

The first thing you’ll notice is how the coding in functions.php starts with a <?php. This starts the php coding.

<?php is followed by, in this example, a /* which indicates the following line is completely ignored. It will keep on ignoring the lines until its ended by a */.

In the code example above, the function indicates the start of a program doing an action.

Following the function, the name of the function is displayed. In the example above, the name of our function is theme_scripts. You can alter the theme name in  theme_scripts to whatever you want. An example would be jonaskjodt_scripts. However, it is preferable to name it something you’ll remember.

Going on with our example, the function of theme_scripts explains how it adds styles and scripts.

The curly bracers { symbol explains what’s inside each script, including that of the function. Once all the codes have been compiled in the function, it’ll end by closing the  { with a another opposite } curly bracer symbol.

Once the entire function has been explained, we add the add_action with accompanying script names to finalize this section of code.

Now that you know where the codes start and stop, you’ll be able to insert your code in the functions.php file in no time.

Feel free to write me in the comments below if you have any issues.

Leave a Reply

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