Where Do I Put That Code?

If you need to ask this question, then you’ve been given code or tasks you haven’t the knowledge to understand, you have research ahead of you, and asking a second time could be very embarrassing.

A lot of the time the problem is because of events. Imagine if you will a list of instructions, not unlike a program:

  1. Go to supermarket
  2. Pick up bread
  3. Pick up milk
  4. Pick up butter
  5. Pay for food

What if I told you that you there was an extra step: when you have picked up an item, cross it off the list, where does this step go?

Does it go on the end? No because then you won’t have crossed anything off the list, what about between 2 and 3? But this step happens every time you pick something up, maybe it goes in three times, after 2, 3 and 4? Asking where do you put it makes no sense.

The answer here is it goes before the work needs to be done, before 1, but precisely where it goes is not important. I could have handed you that step in the carpark, at home, in a bar over drinks 2 weeks ago, it makes no difference. The step itself doesn’t do anything, it sets up a future reaction to an event “when X happens do Y” rather than “Do A, then B, then C”.

So Where Do I Put It?

If you still need to ask this question, you’re likely trying to skip the learning part and save time. Aside from the potential disrespect you’ve just given to the person helping you, you’re actually taking the long route. The obvious fix eluding you for hours because it’s in the first paragraph of the article you didn’t have time to read.

What you need to ask instead, is what are the best resources to learn from. The person who gave you the code will know of some of the best sources, or good ones, saving you time trying to find them. Take advantage of that, and you can save yourself weeks of time.

If you still want to ask the question, and you’re using WordPress, try this handy question, which explains plugins and functions.php, and where code goes.

Leave a Reply

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