WordPress

get_template_part()

Syntax#

  • get_template_part( $slug, $name );
  • get_template_part( $slug );

Parameters#

Parameter Details
$slug (string) Generic template slug name
$name (string) Specialized template name
## Load a template part from a subfolder
get_template_part( 'foo/bar', 'page');

will require ‘bar-page.php’ from the directory ‘foo’.

Get a specific file

You can get specific file using this function.

get_template_part('template-parts/layout');

Include layout.php file from template-parts subdirectory placed in the root of your theme folder.


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