WordPress

get_template_part()

Syntax#

  • get_template_part(‘file-name-no-extension’);

Parameters#

Parameter Description
file-name-no-extension The name of the template part with no extension. E.g. ‘foo’ instead of ‘foo.php’
## Loading Template Part
Pulls the code from a certain specified file into another file where the call was made.

E.g. inside example.php

<h1>Hello World!</h1>

Inside page.php

// header code
get_template_part('example');
// rest of page code

Output:

// header code
<h1>Hello World</h1>
// rest of page code

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow