apply_filters( 'template_include', string $template )

Filters the path of the current template before including it.

Description Description

Parameters Parameters


(string) The path of the template to include.

Top ↑

Source Source

File: wp-includes/template-loader.php

View on Trac

Top ↑

Changelog Changelog

Version Description
3.0.0 Introduced.

Top ↑

More Information More Information

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

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Patrick

    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;

You must log in before being able to contribute a note or feedback.