Created
September 2, 2014 00:10
-
-
Save fikrirasyid/10739e0241bfffeeaa91 to your computer and use it in GitHub Desktop.
WordPress: Use Custom Template From Plugins
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
/** | |
* 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