-
-
Save cheh/9364098 to your computer and use it in GitHub Desktop.
WP: Theme Wrapping method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# License: Public Domain | |
# I recommend replacing 'my_' with your own prefix. | |
function my_template_path() { | |
return My_Wrapping::$main_template; | |
} | |
function my_template_base() { | |
return My_Wrapping::$base; | |
} | |
class My_Wrapping { | |
/** | |
* Stores the full path to the main template file | |
*/ | |
static $main_template; | |
/** | |
* Stores the base name of the template file; e.g. 'page' for 'page.php' etc. | |
*/ | |
static $base; | |
static function wrap( $template ) { | |
self::$main_template = $template; | |
self::$base = substr( basename( self::$main_template ), 0, -4 ); | |
if ( 'index' == self::$base ) | |
self::$base = false; | |
$templates = array( 'wrapper.php' ); | |
if ( self::$base ) | |
array_unshift( $templates, sprintf( 'wrapper-%s.php', self::$base ) ); | |
return locate_template( $templates ); | |
} | |
} | |
add_filter( 'template_include', array( 'My_Wrapping', 'wrap' ), 99 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment