WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/template include

Contents

Intro

This filter hook is executed immediately before WordPress includes the predetermined template file. This can be used to override WordPress's default template behavior.

Examples

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 ( '' != $new_template ) {
			return $new_template ;
		}
	}

	return $template;
}

Source Files

This filter is applied in wp-includes/template-loader.php

Related

See also index of Function Reference and index of Template Tags.