Created
November 17, 2014 10:05
-
-
Save vishalbasnet23/4cf739624ba3b75e75d8 to your computer and use it in GitHub Desktop.
Custom Load Template Function WordPress
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 | |
/*******************************************************************************/ | |
/* Loading templates */ | |
/*******************************************************************************/ | |
add_filter( 'single_template', 'get_custom_post_type_template' ); | |
function get_custom_post_type_template($single_template) { | |
global $post; | |
if ($post->post_type == 'code_gallery') { | |
$single_template = plugin_dir_path( __FILE__ ).'templates/single-codegallery.php'; | |
} | |
return $single_template; | |
} | |
add_filter('template_include', 'wpse50201_set_template'); | |
function wpse50201_set_template( $template ) { | |
//Add option for plug-in to turn this off? If so just return $template | |
//Check if the taxonomy is being viewed | |
//Suggested: check also if the current template is 'suitable' | |
if( is_tax('code_album') && !wpse50201_is_template($template) ) | |
$template = plugin_dir_path(__FILE__ ).'templates/taxonomy-album.php'; | |
return $template; | |
} | |
function wpse50201_is_template( $template_path ){ | |
//Get template name | |
$template = basename($template_path); | |
//Check if template is taxonomy-event-venue.php | |
//Check if template is taxonomy-event-venue-{term-slug}.php | |
if( 1 == preg_match('/^taxonomy-album((-(\S*))?).php/',$template) ) | |
return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment