It is inevitable for codes to get longer as you progress through a project which makes it important to have the codes organize. One way to make the codes maintainable is to separate them in files which will contain code blocks that are related.
This is what I do to avoid the child theme’s functions.php file to get bloated:
#1 I create a new directory in the child theme folder that will contain the sectioned PHP files.
#2 Import the files in the functions.php. It could be done by this code:
require get_stylesheet_directory() . '/inc/thefile.php';
The codes above assumes that there is a directory created in the child theme directory which is inc.
That’s it! The child theme file should should only contain the codes to reference the different files which keeps things pretty organized and more maintainable.
Share this Post