Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#37981 closed defect (bug) (invalid)

template_include not working in customizer previewer

Reported by: jaschaio's profile jaschaio Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6.1
Component: Customize Keywords: close reporter-feedback
Focuses: javascript, administration Cc:

Description

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 Codex:

<?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
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.

Change History (7)

This ticket was mentioned in Slack in #core-customize by jaschaio. View the logs.


8 years ago

#2 follow-up: @westonruter
8 years ago

@jaschaio you have to make sure that the wp_head() and wp_footer() calls are made so that scripts are printed. If customize-preview.js isn't output, then the loaded page won't be able to communicate to the parent frame that the page has finished loading. This issue actually came up recently elsewhere: https://github.com/Automattic/amp-wp/issues/477#issuecomment-247679386

#3 @westonruter
8 years ago

  • Keywords close added

#4 @westonruter
8 years ago

  • Keywords reporter-feedback added

This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.


8 years ago

#6 in reply to: ↑ 2 @jaschaio
8 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Replying to westonruter:

@jaschaio you have to make sure that the wp_head() and wp_footer() calls are made so that scripts are printed. If customize-preview.js isn't output, then the loaded page won't be able to communicate to the parent frame that the page has finished loading. This issue actually came up recently elsewhere: https://github.com/Automattic/amp-wp/issues/477#issuecomment-247679386

Thank you so much. This was the problem, the included template didn't called wp_footer(). I looked everywhere for the solution as I couldn't manage to make it work and can't believe that it was that simple. I would never found that solution myself, maybe its something worth adding to the template_include codex page or on the customizer page itself.

#7 @swissspidy
8 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.