Support » Fixing WordPress » template_include not working in customizer previewer

  • I already posted a ticket in Trac, because this is maybe a bug rather than a problem. But I haven’t got a reply yet, so maybe someone else knows whats going on or can at least replicate the problem.

    If I try to include a different page template via the template_include hook, it doesn’t work within the customizer preview.

    I took this example from the Codex:

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

    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:


    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.

Viewing 1 replies (of 1 total)
  • Moderator Jose Castaneda



    Hi there!

    Taking a look over the trac ticket, it looks like you got your answer. Be sure to mark this as resolved. 😉

Viewing 1 replies (of 1 total)
  • The topic ‘template_include not working in customizer previewer’ is closed to new replies.