Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Last active August 29, 2015 14:16
Show Gist options
  • Save imvaskii/c283084541eec16c04c9 to your computer and use it in GitHub Desktop.
Save imvaskii/c283084541eec16c04c9 to your computer and use it in GitHub Desktop.
[Wordpress] script to include template from any location
<?php function register_project_templates(){
//Create the key used for the themes cache
$cache_key = 'page_templates-'.md5( get_theme_root().'/'.get_stylesheet());
$templates = wp_get_theme()->get_page_templates();
if( empty( $templates ) ) {
$templates = array();
}
wp_cache_delete($cache_key, 'themes');
//template file absolute path
$loc_tem = dirname(__FILE__).'/template-locations.php';
$location_template = array( $loc_tem => 'Template Title');
$templates = array_merge($templates, $location_template);
//Add the modified cache to allow wordpress to pick it up for listing available templates
wp_cache_add( $cache_key, $templates, 'themes', 1800 );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment