[wp-trac] [WordPress Trac] #37981: template_include not working in customizer previewer

WordPress Trac noreply at wordpress.org
Thu Sep 8 03:36:00 UTC 2016


#37981: template_include not working in customizer previewer
----------------------------------------+-----------------------------
 Reporter:  jaschaio                    |      Owner:
     Type:  defect (bug)                |     Status:  new
 Priority:  normal                      |  Milestone:  Awaiting Review
Component:  Customize                   |    Version:  4.6.1
 Severity:  normal                      |   Keywords:
  Focuses:  javascript, administration  |
----------------------------------------+-----------------------------
 I have the following problem and I am not sure if its a bug. If I try to
 include a different page template via the template_include hook, it
 doesn't work within the customizer preview.

 I took the example from the
 [https://codex.wordpress.org/Plugin_API/Filter_Reference/template_include
 Codex]:

 {{{#!php
 <?php
 function portfolio_page_template( $template ) {

     if ( is_page( 'portfolio' )  ) {
         $new_template = locate_template( array( 'portfolio-page-
 template.php' ) );
         if ( '' != $new_template ) {
             return $new_template ;
         }
     }

     return $template;
 }
 add_filter( 'template_include', 'portfolio_page_template', 99 );
 }}}

 For this example my "portfolio-page-template.php" only displays the word
 "test":

 {{{#!php
 <?php
 echo "test";
 ?>
 }}}

 If I visit the portfolio page on the frontend it loads the template
 successfully and displays the word "test".

 But when I try to load the same URL within the customizer via the api it
 doesn't loads the template and shows me the home page instead:

 {{{
 wp.customize.previewer.previewUrl.set('http://localhost:8888/portfolio/')
 }}}

 The same happens if I click on a link within the previewer to the
 portfolio page. It doesn't load the template nor the page. Any other link
 or page that doesn't hook into the template_include loads without a
 problem.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37981>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list