How to store / access files in child theme folder

We are moving a HTML/PHP site to WordPress and want to use as much of the current code as possible. We are using the Avada theme, and have created an Avada child theme folder with the 2 required files (functions.php and style.css). After much research to learn exactly how to place our custom .php files inside of WordPress, and call them from the page, we have a few questions:

  1. Can you place custom .php files directly inside the child theme folder? Some of the research we found says you must write your custom PHP functions inside of the functions.php file.
  2. If we are forced to write all functions inside the functions.php file, how do you “call” a function within a function? Using “includes” doesn’t make much sense if all of the functions are inside one file.
  3. If you CAN STORE the custom .php files inside of the child theme folder (as separate files and file names), do you call them with an “include” like you would in regular HTML/PHP site files (not inside of WordPress)? If not, how does this work?
  4. Where in the child theme do you store Javascript files?

2 Answers
2

Can you place custom .php files directly inside the child theme
folder?

Yes, of course you can. WordPress is PHP. What works in PHP works in WordPress.

Some of the research we found says you must write your custom PHP
functions inside of the functions.php file.

Nonsense. Many themes segregate code into multiple files, including “Twenty Fifteen”. This is not only OK but is usually wise as it helps keep your code base organized and manageable.

If we are forced to write all functions inside the functions.php file,
how do you “call” a function within a function? Using “includes”
doesn’t make much sense if all of the functions are inside one file.

This doesn’t make sense. User function definitions in PHP are all global. Once loaded, they can be used anywhere. That is basic PHP (which works like normal in “WordPress”). There should be no issue with “calling” a function within a function. If the function has been defined, just use it.

If you CAN STORE the custom .php files inside of the child theme
folder (as separate files and file names), do you call them with an
“include” like you would in regular HTML/PHP site files (not inside of
WordPress)?

You can, and yes. require, require_once, include, and include_once work in WordPress like normal. WordPress is a PHP application. PHP works in WordPress. I honestly don’t understand why so many people seem to think that it doesn’t… that WordPress somehow breaks PHP.

Where in the child theme do you store Javascript files?

Wherever you want. Usually a folder named something like “js” or “javascript”, but that is up to you. You could store it in a folder named “fred” if you want or in no folder at all.

Leave a Comment