Split your functions.php file in to multiple files
Code snippets should be placed in your functions.php
file or extracted in to your own custom plugin.
Create a folder in your theme’s root and name it functions
. We’re going to split our functions in to multiple logical .php files and put them all in this folder.
Create a new .php file for each category of functionality as you see fit and copy paste the code from your main functions file. Below is an example from one of my own projects.
Leave your main functions.php in the root of your theme.
Add the code below to your original functions.php file. This snippet will find all files with a .php extension and require them – giving you the same functions.php, but more manageable.
$path = get_theme_file_path() . '/functions/*.php';
foreach (glob($path) as $filename){
require $filename;
}
In terms of a performance hit, the overhead using glob()
is negligible.