The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Include template parts with PHP (4 posts)

  1. theodorlindekaer
    Posted 3 years ago #

    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!

  2. paulwpxp
    Font hero
    Posted 3 years ago #

    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.

  3. theodorlindekaer
    Posted 3 years ago #

    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.


  4. paulwpxp
    Font hero
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic