WordPress Single Template By Post Format

Last modified: 
Thursday, April 9th, 2015

This function allows you to use custom WordPress post format templates and suggestions for single.php.

# Place in functions.php
/*
* This snippet allows you to use custom templates for single.php by
* post format like this: single-post-format-quote.php.
*
*/
add_filter('single_template', 'single_template_terms');
function single_template_terms($template) {
    $taxonomies = (array) wp_get_object_terms(get_the_ID(),
                          get_taxonomies(array('public' => true, '_builtin' => true)));
    foreach( $taxonomies as $term ) {
        if ( file_exists(TEMPLATEPATH . "/single-{$term->slug}.php") )
            return TEMPLATEPATH . "/single-{$term->slug}.php";
    }
    return $template;
}

References

single.php 'post-format' template for builtin Post Formats


The operator of this site makes no claims, promises, or guarantees of the accuracy, completeness, originality, uniqueness, or even general adequacy of the contents herein and expressly disclaims liability for errors and omissions in the contents of this website.