Skip to content

Instantly share code, notes, and snippets.

@unr
Last active August 29, 2015 14:02
Show Gist options
  • Save unr/00a64b479f5841722d42 to your computer and use it in GitHub Desktop.
Save unr/00a64b479f5841722d42 to your computer and use it in GitHub Desktop.
An example of using classes to bootstrap a WordPress Theme.
<?php
/**
* Our main class for our theme.
*
* This will act as our controller, and activate other hooks/functions for wordpress.
*/
class Example {
// Called by our bootstrap_theme function
public static function init() {
echo "Hello World";
}
}
<?php
/**
* Our functions file. We're hooking into the wp after_setup_theme
* hook to bootstrap our theme, instead of just firing everything
* all willy-nilly.
*/
// Bootstrap our theme, this is called by the after_setup_theme hook
function bootstrap_theme {
// Include our class file, which we use to control our theme
require_once locate_template('/lib/theme/class.php');
Example::init();
}
add_action( 'after_setup_theme', 'bootstrap_theme' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment