Skip to content

Instantly share code, notes, and snippets.

@BinaryKitten
Created December 4, 2015 11:23
Show Gist options
  • Select an option

  • Save BinaryKitten/1fd2d64440ae921ecec8 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryKitten/1fd2d64440ae921ecec8 to your computer and use it in GitHub Desktop.
ThemeAutoloader
<?php
spl_autoload_register( 'my_theme_autoloader' );
function my_theme_autoloader( $class_name ) {
if ( substr( $class_name, 0, 6 ) == 'theme_' ) {
$cur_theme_file = get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_name . '.php';
$parent_theme_file = get_template_directory() . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . $class_name . '.php';
if ( file_exists( $cur_theme_file ) ) {
require_once $cur_theme_file;
} elseif ( file_exists( $parent_theme_file ) ) {
require_once $parent_theme_file;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment