Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created November 17, 2014 10:05
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 vishalbasnet23/4cf739624ba3b75e75d8 to your computer and use it in GitHub Desktop.
Save vishalbasnet23/4cf739624ba3b75e75d8 to your computer and use it in GitHub Desktop.
Custom Load Template Function WordPress
<?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