Support » Themes and Templates » Include template parts with PHP

  • I see that many themes use:


    When I create a now part (fx banner.php) the following does not work:


    Instead I have to use:


    My question is: why is get_header used and not just consistently get_template_part(‘header’)? What is the purpose of this GET function?

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • To load a php file in your own theme, use locate_template()

    The get_template_part(), get_header(), and such all make use of locate_template() with a systematic order of slugs.

    See wp-includes/general-template.php for more details.

    when I use:

    locate_template(‘banner’) I am not able to fetch my own banner.php.

    When I use:

    get_template_part(‘banner’) it works great.


    The first parameter is array, also the second must be true for it to load ( see the doc in the link above )

    locate_template( array( 'banner.php' ), true, false );

    There is nothing wrong with get_template_part() though, it has more fancy loading order based on slugs. I would just use locate_template() because most of the time when loading special php file in theme ( like the splash banner in front page for example ) won’t be needing that fancy checking.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Include template parts with PHP’ is closed to new replies.