Skip to content

Instantly share code, notes, and snippets.

@ellefsen
Forked from scribu/wrapping.php
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellefsen/8a5ae50590783ec17d18 to your computer and use it in GitHub Desktop.
Save ellefsen/8a5ae50590783ec17d18 to your computer and use it in GitHub Desktop.
<?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