A super minimal functions.php file

In my last post I talked about strategies to organize your WordPress theme’s functions.php file by following object-oriented programming principles. If you prefer to stick with a procedural coding style, here is a simple way to keep your functions.php file lean and mean.

Simply save each hooked function in a separate file, then use PHP includes to import them into functions.php:

require_once('includes/custom_excerpt_length.php');
require_once('includes/another_function.php');
require_once('includes/a_third_function.php');
// etc.

It doesn’t get much more minimal than that!

In this example our custom_excerpt_length.php file might look like this:

function custom_excerpt_length () {
  return 10;
}
add_filter('excerpt_length', 'custom_excerpt_length');

One thought on “A super minimal functions.php file

  1. Wajiha says:

    Very useful snippet if you want to add multiple functionality code snippets into your functions.php file.

Comments are closed.