Created
November 12, 2012 15:47
-
-
Save rachelbaker/4060089 to your computer and use it in GitHub Desktop.
WordPress display plugin template file for custom post type
This file contains hidden or 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 | |
| add_filter('template_include', array($this, 'get_customer_review_cpt_template'), 100); | |
| public function get_customer_review_cpt_template($template) | |
| { | |
| global $template; | |
| // Our custom post type. | |
| $post_type = 'customer_reviews'; | |
| $post_object = $GLOBALS['post']; | |
| // check if the custom post type is set in query_vars - if not return early | |
| if ( !isset( $post_object->post_type ) ) { | |
| return $template; | |
| } | |
| // check if looking for single template for custom post type - if so return plugin template file | |
| if ( is_singular() && $post_object->post_type === $post_type ) { | |
| return dirname(__FILE__) . "/views/single-$post_type.php"; | |
| } | |
| return $template; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment