Last active
August 29, 2015 14:16
-
-
Save imvaskii/c283084541eec16c04c9 to your computer and use it in GitHub Desktop.
[Wordpress] script to include template from any location
This file contains hidden or 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 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