1

In my WordPress theme I created the custom post type articles. I also created two taxonomies called article & news. How can I display each taxonomy in its own single template? For now it only displays using the single-articles.php template.

1

Use the single_template filter in your functions file with the correct conditional tag

add_filter( 'single_template', 'single_tax_term_template' );
function single_tax_term_template( $single_template ) {

    global $post;

   if ( has_term( '', 'article' )  ) {
          $single_template = dirname( __FILE__ ) . '/article.php';
     }

    if ( has_term( '', 'news' )  ) {
          $single_template = dirname( __FILE__ ) . '/news.php';
     }

    return $single_template;
}

This code targets all terms in news and article taxonomies.

-1

You will need to read the taxonomy template article on WordPress.org for that information.

  • This article doesn't contain an answer to the question related to the single post template. – Milan Petrovic Sep 12 '17 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.