load_template

Require the template file with WordPress environment.

Description

load_template( (string) $_template_file, (bool) $require_once = true ); 

The globals are set up for the template file to ensure that the WordPress environment is available from within the function. The query variables are also available.

Parameters (2)

0. $template_file (string)
Path to template file.
1. $require_once — Optional. (bool) => true
Whether to require_once or require. Default true.

Usage

  1. if ( !function_exists( 'load_template' ) ) { 
  2. require_once ABSPATH . WPINC . '/template.php'; 
  3.  
  4. // Path to template file. 
  5. $template_file = ''; 
  6.  
  7. // Whether to require_once or require. Default true. 
  8. $require_once = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = load_template($template_file, $require_once); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/template.php  
  1. function load_template( $_template_file, $require_once = true ) { 
  2. global $posts, $post, $wp_did_header, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID; 
  3.  
  4. if ( is_array( $wp_query->query_vars ) ) { 
  5. extract( $wp_query->query_vars, EXTR_SKIP ); 
  6.  
  7. if ( isset( $s ) ) { 
  8. $s = esc_attr( $s ); 
  9.  
  10. if ( $require_once ) { 
  11. require_once( $_template_file ); 
  12. } else { 
  13. require( $_template_file );