Can I have an additional functions.php file in Wordpress?

There're quite a lot of functions, and so, does my theme, it all gets a little cluttered even with all the comments. Additionally, every time the theme is updated, the new functions.php file would replace the current one.

So, it becomes a pain.

Hence, I thought, would it be possible to have a 2nd/3rd functions.php file? Using PHP include or require function. That way, I can categorise the functions and they won't be affected on theme update.

So,

?php include 'functions_1.php' ?

Thanks,

Topic include functions Wordpress

Category Web


You can get rid of the theme update situation by using a child theme. Your child theme will work as an extension of the parent theme that you update often. You can learn more about child theme from here.

But if you don't wanna use child theme then yes, you can add as many additional functions file as you want. A regular include or require will just work fine. You can include file using a relative path or you can use get_template_directory() function for an absolute path. For instance

include get_template_directory() . '/inc/functions-1.php'; // if it's inside inc directory
include get_template_directory() . '/functions-1.php'; // Or if it's not inside any directory

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.