//set single template for custom post type texonomy function get_custom_single_template($single_template) { global $post; if ($post->post_type == 'resources') { $terms = get_the_terms($post->ID, 'resources-category'); if($terms && !is_wp_error( $terms )) { //Make a foreach because $terms is an array but it supposed to be only one term foreach($terms as $term){ $single_template = dirname( __FILE__ ) . '/single-'.$term->slug.'.php'; } } } return $single_template; } add_filter( "single_template", "get_custom_single_template" ) ;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter