Skip to content

Instantly share code, notes, and snippets.

@rachelbaker
Created November 12, 2012 15:47
Show Gist options
  • Select an option

  • Save rachelbaker/4060089 to your computer and use it in GitHub Desktop.

Select an option

Save rachelbaker/4060089 to your computer and use it in GitHub Desktop.
WordPress display plugin template file for custom post type
<?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