Skip to content

Instantly share code, notes, and snippets.

@bmarshall511
Created April 4, 2017 19:13
Show Gist options
  • Save bmarshall511/eff4f2f7c066e2cc5a68af7f90583d89 to your computer and use it in GitHub Desktop.
Save bmarshall511/eff4f2f7c066e2cc5a68af7f90583d89 to your computer and use it in GitHub Desktop.
Override WordPress template files.
<?php
/**
* Template loader.
*
* The template loader will check if WP is loading a template
* for a specific Post Type and will try to load the template
* from out 'templates' directory.
*
* @since 1.0.0
*
* @param string $template Template file that is being loaded.
* @return string Template file that should be loaded.
*/
function PLUGIN_template_loader( $template ) {
$find = array();
$file = '';
if( is_singular() ):
$file = 'single-plugin.php';
elseif( is_tax() ):
$file = 'archive-plugin.php';
endif;
if ( file_exists( PLUGIN_locate_template( $file ) ) ) :
$template = PLUGIN_locate_template( $file );
endif;
return $template;
}
add_filter( 'template_include', 'PLUGIN_template_loader' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment