Skip to content

Instantly share code, notes, and snippets.

@feliciaceballos
Last active April 27, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feliciaceballos/23a34338f904871a7326ce8029b3c08f to your computer and use it in GitHub Desktop.
Save feliciaceballos/23a34338f904871a7326ce8029b3c08f to your computer and use it in GitHub Desktop.
Reference Custom Single Post Templates
// Define a constant path to plugin folder
define(SINGLE_PATH, plugin_dir_path( __FILE__ ). '/templates');
// Filter the single_template with our custom function
add_filter('single_template', 'my_single_template');
function my_single_template($single) {
global $wp_query, $post;
$user_role = get_user_role();
$category = get_the_category();
$sticky = is_sticky();
$tag = has_tag( 'tag-name' );
$post_status = get_post_status () == 'future';
if ($post->post_type == 'client' && $user_role == 'client') :
return SINGLE_PATH . '/client-portal.php';
elseif (in_category('export') && $post->post_type == 'client' ) :
return SINGLE_PATH . '/export.php';
elseif (in_category('new-lead') && $post->post_type == 'client' ) :
return SINGLE_PATH . '/print-lead-sheet.php';
else :
return SINGLE_PATH . '/lead-sheet.php';
endif;
return $single;
}
// Get user role
function get_user_role() {
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
return $user_role;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment