1

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?
1

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.

  • You are amazing! We have been searching codex, blogs, other sites for the answers to these questions, and you covered them all in one swoop! Thank you so much. This has been very informative and helpful. We truly appreciate it and will keep this forum directly on our desktop for future reference. Hail to stackexchange.com!!! and to Gabrial, Vee and s_ha_dum!!! Thank you all! – WebDev Jul 2 '15 at 22:00
0
  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.

You can put in the folder directly and use it. Child theme templates work in a hierarchy. Child theme overrides the parent theme folder, so if you want to modify a file you can copy the files into child theme folder and modify it. (If possible and available, use the hooks to inherit the codes instead of directly copied the files.)

  1. 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 is a standard practice to include all the functions in function.php. If you want to break, you can break it. For example:

define('FUNCTIONS_PATH', get_template_directory() . '/functions/' );

require_once (FUNCTIONS_PATH.'post-types.php');
require_once (FUNCTIONS_PATH.'metaboxes.php');
require_once (FUNCTIONS_PATH.'theme-functions.php');
require_once (FUNCTIONS_PATH.'theme-widgets.php');
require_once (FUNCTIONS_PATH.'activation-plugin.php');

You can put functions in different file and call theme here.

  1. 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?

For including the files in child theme, follow this approach from WordPress Codex

require_once( get_stylesheet_directory() . '/my_included_file.php' );

4.Where in the child theme do you store Javascript files? You can put any where you want for example in a folder name js, javascript, scripts, lib etc or follow the approach same as parent theme.

If you want anything more please comment.

I hope these will satisfy.

Thanks

Vee

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.