Languages: English • 한국어 • (Add your language)
This filter hook is executed immediately before WordPress includes the predetermined template file. This can be used to override WordPress's default template behavior.
This example includes a new template on a page called 'portfolio' if the new template file was found.
add_filter( 'template_include', 'portfolio_page_template', 99 ); function portfolio_page_template( $template ) { if ( is_page( 'portfolio' ) ) { $new_template = locate_template( array( 'portfolio-page-template.php' ) ); if ( !empty( $new_template ) ) { return $new_template; } } return $template; }
This filter is applied in wp-includes/template-loader.php