0

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,

  • 1
    Are you using a child theme? – Milo Feb 11 '18 at 0:26
  • @Milo No child theme used – Haneef Ibn Ahmad Feb 11 '18 at 0:28
  • 1
    If you want to add functionality to a theme modifying it in any way (even just to include other files) is not the way to do it. This is what child themes are for. – Jacob Peattie Feb 11 '18 at 2:18
  • 1
    yes, you can include other files. it's just like any other php file. – inarilo Feb 11 '18 at 4:51
0

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

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.