Is your function.php file too big and unmanageable?
My WordPress function.php file was starting to overwhelm me. It was impossible to see at a glance what functions were being used and where functions started and ended. So it got me thinking, is there a way to break-up my function.php file into smaller, more manageable chunks?
The short answer is yes.
How to split-up the function.php file
First, create a new folder within your WordPress theme. I called my folder ‘/includes’ but you can name it whatever you want.
Next, create individual php files for each function you want to move.
For example all the code in my theme related to breadcrumbs was removed from the function.php file and added to the new file called /includes/breadcrumbs.php.
Your theme directory should start to look something like this:
- index.php
- function.php
- /includes
- breadcrumbs.php
- comments.php
Finally you need to reference each newly created file by adding the following to your function.php file.
<?php
require_once( __DIR__ . '/includes/breadcrumbs.php');
require_once( __DIR__ . '/includes/comments.php');
?>
This approach can be done in stages so you don’t have to move all your functions in one go.
