Skip to content

Instantly share code, notes, and snippets.

@fikrirasyid
Created September 2, 2014 00:10
Show Gist options
  • Save fikrirasyid/10739e0241bfffeeaa91 to your computer and use it in GitHub Desktop.
Save fikrirasyid/10739e0241bfffeeaa91 to your computer and use it in GitHub Desktop.
WordPress: Use Custom Template From Plugins
/**
* Route single page to custom template
*
* @return string of path
*/
function fr_route_template( $single_template ){
// Put any conditional tag here. This one assumes you want to serve custom template for CPT titled "newsletter"'s single page
if( is_singular( 'newsletter' ) ){
// Get template path, assuming the structure is /wp-content/your-plugin/templates/single.php
$template_path = plugin_dir_path( __FILE__ ) . 'templates/single.php';
return $template_path;
} else {
return $single_template;
}
}
add_filter( 'template_include', 'fr_route_template' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment