Last active
October 9, 2015 10:37
-
-
Save aaroneaton/3489926 to your computer and use it in GitHub Desktop.
WP:Include template files from plugin
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 | |
// In this situation, template files for your custom post type will live in the root of your plugin directory. | |
// Ideally they would be in a subdirectory. | |
add_filter( 'archive_template', 'get_archive_template' ); | |
function get_archive_template( $archive_template ) { | |
global $post; | |
$plugindir = dirname( __FILE__ ); | |
if( get_query_var( 'post_type' ) == 'your_custom_post_type' ) { | |
$archive_template = $plugindir . '/custom_post_type_archive.php'; | |
} | |
return $archive_template; | |
} | |
add_filter( 'search_template', 'get_search_template' ); | |
function get_search_template( $search_template ) { | |
global $post; | |
$plugindir = dirname( __FILE__ ); | |
if( get_query_var( 'post_type' ) == 'your_custom_post_type' ) { | |
$search_template = $plugindir . '/custom_post_type_archive.php'; | |
} | |
return $search_template; | |
} | |
add_filter( 'single_template', 'get_single_template' ); | |
function get_single_template( $single_template ) { | |
global $post; | |
$plugindir = dirname( __FILE__ ); | |
if( get_query_var( 'post_type' ) == 'your_custom_post_type' ) { | |
$single_template = $plugindir . '/custom_post_type_single.php'; | |
} | |
return $single_template; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment