An example – to be used in functions.js – to customize both the archive and the single templates for a custom post type registered as my-post-type.

App.filter( 'template', function( template, current_screen ) {
      if ( current_screen.component_id === 'my-post-type-component-slug' ) {
            template = 'my-post-type-archive'; //Don't need .html here.
      } else if ( TemplateTags.isPostType('my-post-type', 0, current_screen ) ) {
            template = 'my-post-type-single'; //Don't need .html here.
      }
      return template;
} );

 

Published by Benjamin on May 26, 2017

Head of Digital for a press group, WordPress since 2008, WordCamp organizer, developer for the fun

2 Comments

  1. Instead of bugging you on email again 😛 I thought I’d ask here.

    I used my code like this;

    App.filter( 'template', function( template, current_screen ) {
          if( current_screen.component_id === 'events' ) ){
                template = 'events-archive'; //Don't need .html here.
          } else if ( TemplateTags.isPostType('events', 0, current_screen ) {
                template = 'events-single'; //Don't need .html here.
          }
          return template;
    } );

    When I then load my app the menu does not work. The plugin I’m using is called events manager and its slug is “events”

    Reply
    • Hi Edward,
      Actually it will be more convenient if you can send your question to our support email, so that we can narrow down what’s not working in your exact situation.
      We’ll then post the answer here if it can help others 🙂

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Having questions?

FAQ | Tutorials | Documentation

Or

Contact Us