Skip to main content
Fixed typo of __DIR___ to __DIR__.
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
<?php 
/*
 * functions.php
 * 
 */
require_once( __DIR_____DIR__ . '/includes/null-meta-compare.php');
require_once( __DIR_____DIR__ . '/includes/older-examples.php');
require_once( __DIR_____DIR__ . '/includes/wp-admin-menu-classes.php');
require_once( __DIR_____DIR__ . '/includes/admin-menu-function-examples.php');

// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once( __DIR_____DIR__ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR_____DIR__ . '/includes/category-fields.php');
require_once( __DIR_____DIR__ . '/includes/post-list-shortcode.php');
require_once( __DIR_____DIR__ . '/includes/car-type-urls.php');
require_once( __DIR_____DIR__ . '/includes/buffer-all.php');
require_once( __DIR_____DIR__ . '/includes/get-page-selector.php');

// http://wordpress.stackexchange.com/questions/907/
require_once( __DIR_____DIR__ . '/includes/top-5-posts-per-category.php'); 

// http://wordpress.stackexchange.com/questions/951/
require_once( __DIR_____DIR__ . '/includes/alternate-category-metabox.php');  

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once( __DIR_____DIR__ . '/includes/remove-status.php');  

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR_____DIR__ . '/includes/301-redirects.php');  
<?php 
/*
 * functions.php
 * 
 */
require_once( __DIR___ . '/includes/null-meta-compare.php');
require_once( __DIR___ . '/includes/older-examples.php');
require_once( __DIR___ . '/includes/wp-admin-menu-classes.php');
require_once( __DIR___ . '/includes/admin-menu-function-examples.php');

// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once( __DIR___ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR___ . '/includes/category-fields.php');
require_once( __DIR___ . '/includes/post-list-shortcode.php');
require_once( __DIR___ . '/includes/car-type-urls.php');
require_once( __DIR___ . '/includes/buffer-all.php');
require_once( __DIR___ . '/includes/get-page-selector.php');

// http://wordpress.stackexchange.com/questions/907/
require_once( __DIR___ . '/includes/top-5-posts-per-category.php'); 

// http://wordpress.stackexchange.com/questions/951/
require_once( __DIR___ . '/includes/alternate-category-metabox.php');  

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once( __DIR___ . '/includes/remove-status.php');  

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR___ . '/includes/301-redirects.php');  
<?php 
/*
 * functions.php
 * 
 */
require_once( __DIR__ . '/includes/null-meta-compare.php');
require_once( __DIR__ . '/includes/older-examples.php');
require_once( __DIR__ . '/includes/wp-admin-menu-classes.php');
require_once( __DIR__ . '/includes/admin-menu-function-examples.php');

// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once( __DIR__ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR__ . '/includes/category-fields.php');
require_once( __DIR__ . '/includes/post-list-shortcode.php');
require_once( __DIR__ . '/includes/car-type-urls.php');
require_once( __DIR__ . '/includes/buffer-all.php');
require_once( __DIR__ . '/includes/get-page-selector.php');

// http://wordpress.stackexchange.com/questions/907/
require_once( __DIR__ . '/includes/top-5-posts-per-category.php'); 

// http://wordpress.stackexchange.com/questions/951/
require_once( __DIR__ . '/includes/alternate-category-metabox.php');  

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once( __DIR__ . '/includes/remove-status.php');  

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR__ . '/includes/301-redirects.php');  
Changed code to require absolute references vs. relative references.
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132
<?php 
/*
 * functions.php
 * 
 */
require_once('includes __DIR___ . '/includes/null-meta-compare.php');
require_once('includes __DIR___ . '/includes/older-examples.php');
require_once('includes __DIR___ . '/includes/wp-admin-menu-classes.php');
require_once('includes __DIR___ . '/includes/admin-menu-function-examples.php');
require_once('includes/cpt-filtering-in-admin.php');  
// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once('includes __DIR___ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR___ . '/includes/category-fields.php');
require_once('includes __DIR___ . '/includes/post-list-shortcode.php');
require_once('includes __DIR___ . '/includes/car-type-urls.php');
require_once('includes __DIR___ . '/includes/buffer-all.php');
require_once('includes __DIR___ . '/includes/get-page-selector.php');
require_once('includes/top-5-posts-per-category.php');  
// http://wordpress.stackexchange.com/questions/907/
require_once('includes __DIR___ . '/alternateincludes/top-category5-metaboxposts-per-category.php');   

// http://wordpress.stackexchange.com/questions/951/
require_once('includes __DIR___ . '/removeincludes/alternate-statuscategory-metabox.php');   

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once('includes __DIR___ . '/301includes/remove-redirectsstatus.php');   

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR___ . '/includes/301-redirects.php');  
<?php 
/*
 * functions.php
 * 
 */
require_once('includes/null-meta-compare.php');
require_once('includes/older-examples.php');
require_once('includes/wp-admin-menu-classes.php');
require_once('includes/admin-menu-function-examples.php');
require_once('includes/cpt-filtering-in-admin.php'); // WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?http://wordpress.stackexchange.com/questions/578/
require_once('includes/category-fields.php');
require_once('includes/post-list-shortcode.php');
require_once('includes/car-type-urls.php');
require_once('includes/buffer-all.php');
require_once('includes/get-page-selector.php');
require_once('includes/top-5-posts-per-category.php'); // http://wordpress.stackexchange.com/questions/907/
require_once('includes/alternate-category-metabox.php');  // http://wordpress.stackexchange.com/questions/951/
require_once('includes/remove-status.php');  // http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once('includes/301-redirects.php');  // http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
<?php 
/*
 * functions.php
 * 
 */
require_once( __DIR___ . '/includes/null-meta-compare.php');
require_once( __DIR___ . '/includes/older-examples.php');
require_once( __DIR___ . '/includes/wp-admin-menu-classes.php');
require_once( __DIR___ . '/includes/admin-menu-function-examples.php');
 
// WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?
// http://wordpress.stackexchange.com/questions/578/
require_once( __DIR___ . '/includes/cpt-filtering-in-admin.php'); 
require_once( __DIR___ . '/includes/category-fields.php');
require_once( __DIR___ . '/includes/post-list-shortcode.php');
require_once( __DIR___ . '/includes/car-type-urls.php');
require_once( __DIR___ . '/includes/buffer-all.php');
require_once( __DIR___ . '/includes/get-page-selector.php');
 
// http://wordpress.stackexchange.com/questions/907/
require_once( __DIR___ . '/includes/top-5-posts-per-category.php');  

// http://wordpress.stackexchange.com/questions/951/
require_once( __DIR___ . '/includes/alternate-category-metabox.php');   

// http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once( __DIR___ . '/includes/remove-status.php');   

// http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate
require_once( __DIR___ . '/includes/301-redirects.php');  
Source Link
MikeSchinkel
  • 37.5k
  • 14
  • 116
  • 132

If you are getting to the point where the code in your theme's functions.php is starting to overwhelm you I would definitely say you are ready to consider splitting it up into multiple files. I tend to do that almost by second nature at this point.

###Use Include Files in your Theme's functions.php File I create a subdirectory called "includes" under my theme directory and segment my code into include files organized by what makes sense to me at the time (which means I'm constantly refactoring and moving code around as a site evolves.) I also rarely put any real code in functions.php; everything goes in the include files; just my preference.

Just to give you an example here's my test install that I use to test my answers to questions here on WordPress Answers. Every time I answer a question I keep the code around in case I need it again. This isn't exactly what you'll do for a live site but it shows the mechanics of splitting up the code:

<?php 
/*
 * functions.php
 * 
 */
require_once('includes/null-meta-compare.php');
require_once('includes/older-examples.php');
require_once('includes/wp-admin-menu-classes.php');
require_once('includes/admin-menu-function-examples.php');
require_once('includes/cpt-filtering-in-admin.php'); // WA: Adding a Taxonomy Filter to Admin List for a Custom Post Type?http://wordpress.stackexchange.com/questions/578/
require_once('includes/category-fields.php');
require_once('includes/post-list-shortcode.php');
require_once('includes/car-type-urls.php');
require_once('includes/buffer-all.php');
require_once('includes/get-page-selector.php');
require_once('includes/top-5-posts-per-category.php'); // http://wordpress.stackexchange.com/questions/907/
require_once('includes/alternate-category-metabox.php');  // http://wordpress.stackexchange.com/questions/951/
require_once('includes/remove-status.php');  // http://lists.automattic.com/pipermail/wp-hackers/2010-August/034384.html
require_once('includes/301-redirects.php');  // http://wordpress.stackexchange.com/questions/1027/removing-the-your-backup-folder-might-be-visible-to-the-public-message-generate

###Or Create Plugins Another option it to start grouping your code by function and create your own plugins. For me I start coding in the theme's functions.php file and by the time I get the code fleshed out I've moved most of my code into plugins.

###However NO Significant Performance Gain From PHP Code Organization On the other hand structuring your PHP files is 99% about creating order and maintainability and 1% about performance, if that (organizing .js and .css files called by the browser via HTTP is a completely different case and has huge performance implications.) But how you organize your PHP code on the server pretty much doesn't matter from a performance perspective.

###And Code Organization is Personal Preference And last but not least code organization is personal preference. Some people would hate how I organize code just as I might hate how they do it too. Find something you like and stick with it, but allow your strategy to evolve over time as you learn more and get more comfortable with it.