Keeping child theme’s functions.php neat

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

Comments 2

  1. Hey there! I could have sworn I’ve been to this website before
    but after reading through some of the post I realized it’s new to me.
    Nonetheless, I’m definitely glad I found it and I’ll be bookmarking and checking back frequently!

  2. Pingback: My Homepage

Leave a Reply

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