Title: get_template_part
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_template_part( string $slug, string|null $name = null, array $args = array() ): void|false

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#more-information)
    - [Usage](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#usage)
 * [Source](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#wp--skip-link--target)

Loads a template part into a template.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#description)󠁿

Provides a simple mechanism for child themes to overload reusable sections of code
in the theme.

Includes the named template part for a theme or if a name is specified then a specialized
part will be included. If the theme contains no {slug}.php file then no template
will be included.

The template is included using require, not require_once, so you may include the
same template part multiple times.

For the $name parameter, if the file is called “{slug}-special.php” then specify“
special”.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#parameters)󠁿

 `$slug`stringrequired

The slug name for the generic template.

`$name`string|nulloptional

The name of the specialized template.

Default:`null`

`$args`arrayoptional

Additional arguments passed to the template.

Default:`array()`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#return)󠁿

 void|false Void on success, false if the template does not exist.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#more-information)󠁿

### 󠀁[Usage](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#usage)󠁿

    ```php
    get_template_part( $slug );
    ```

    ```php
    get_template_part( $slug, $name );
    ```

Note: `get_template_part()` fails silently

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#source)󠁿

    ```php
    function get_template_part( $slug, $name = null, $args = array() ) {
    	/**
    	 * Fires before the specified template part file is loaded.
    	 *
    	 * The dynamic portion of the hook name, `$slug`, refers to the slug name
    	 * for the generic template part.
    	 *
    	 * @since 3.0.0
    	 * @since 5.5.0 The `$args` parameter was added.
    	 *
    	 * @param string      $slug The slug name for the generic template.
    	 * @param string|null $name The name of the specialized template
    	 *                          or null if there is none.
    	 * @param array       $args Additional arguments passed to the template.
    	 */
    	do_action( "get_template_part_{$slug}", $slug, $name, $args );

    	$templates = array();
    	$name      = (string) $name;
    	if ( '' !== $name ) {
    		$templates[] = "{$slug}-{$name}.php";
    	}

    	$templates[] = "{$slug}.php";

    	/**
    	 * Fires before an attempt is made to locate and load a template part.
    	 *
    	 * @since 5.2.0
    	 * @since 5.5.0 The `$args` parameter was added.
    	 *
    	 * @param string   $slug      The slug name for the generic template.
    	 * @param string   $name      The name of the specialized template
    	 *                            or an empty string if there is none.
    	 * @param string[] $templates Array of template files to search for, in order.
    	 * @param array    $args      Additional arguments passed to the template.
    	 */
    	do_action( 'get_template_part', $slug, $name, $templates, $args );

    	if ( ! locate_template( $templates, true, false, $args ) ) {
    		return false;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L167)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L167-L209)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#hooks)󠁿

 [do_action( ‘get_template_part’, string $slug, string $name, string[] $templates, array $args )](https://developer.wordpress.org/reference/hooks/get_template_part/)

Fires before an attempt is made to locate and load a template part.

 [do_action( “get_template_part_{$slug}”, string $slug, string|null $name, array $args )](https://developer.wordpress.org/reference/hooks/get_template_part_slug/)

Fires before the specified template part file is loaded.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#related)󠁿

| Uses | Description | 
| [locate_template()](https://developer.wordpress.org/reference/functions/locate_template/)`wp-includes/template.php` |

Retrieves the name of the highest priority template file that exists.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | The `$args` parameter was added. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#user-contributed-notes)󠁿

 1.    [Skip to note 17 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4130)
 2.     [Vinobe](https://profiles.wordpress.org/tomcent/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4130)
 3.   [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4130)
      Vote results for this note: 61[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4130)
 4.   **Passing variables after WordPress 5.5 update**
       ===========================
      ===========
 5.   **When calling function**
 6.       ```php
          get_template_part(
          	'template-part',
          	'name',
          	array(
          		'key'	=> 'value',
          		'key2'	=> 'value2'
          	)
          );
          ```
      
 7.   **In your template part**
 8.       ```php
          var_dump( $args );	// Everything
          echo $args['key'];	// Specific values
          ```
      
 9.    [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4130%23feedback-editor-4130)
 10.   [Skip to note 18 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-358)
 11.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-358)
 12.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-358)
      Vote results for this note: 60[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-358)
 13.  **Using with theme subfolders**
 14.  To use this function with subfolders in your theme directory, simply prepend 
      the folder name before the slug. For example, if you have a folder called “partials”
      in your theme directory and a template part called “content-page.php” in that
      sub-folder, you would use `get_template_part()` like this:
 15.      ```php
          <?php get_template_part( 'partials/content', 'page' ); ?>
          ```
      
 16.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D358%23feedback-editor-358)
 17.   [Skip to note 19 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-2349)
 18.    [Pedro Carvalho](https://profiles.wordpress.org/pcarvalho/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-2349)
 19.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-2349)
      Vote results for this note: 34[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-2349)
 20.  _the old codex had this entry about “Passing Variables to Template”_
 21.  Because the template is being required, it will not have access to any variables
      you define within the calling theme’s PHP code, unless you explicitly declare
      them as global.
 22.  However, [load_template()](https://developer.wordpress.org/reference/functions/load_template/),
      which is called indirectly by [get_template_part()](https://developer.wordpress.org/reference/functions/get_template_part/)
      extracts all of the [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)
      query variables, into the scope of the loaded template. So you can use [set_query_var()](https://developer.wordpress.org/reference/functions/set_query_var/)
      to make your variable available to the template part.
 23.      ```php
          // You wish to make $my_var available to the template part at `content-part.php`
          set_query_var( 'my_var', $my_var );
          get_template_part( 'content', 'part' );
          ```
      
 24.   * Minor suggestion, it should rather be ‘Because _of where in the code execution_
         the template is being required’. The fact that is is being required vs being
         included is not the reason one has to use the [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)
         query variables.
       * [Jonathan Bossenger](https://profiles.wordpress.org/psykro/) [7 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-3303)
       * // Since WP version 5.5, we can set the args directly like the following //
         Note: array method requires PHP 7.* $args = [ ‘my_var_1’ => $my_var_1, ‘my_var_2’
         => $my_var_2, ]; get_template_part( ‘content’, ‘part’, $args );
       * [Santukon](https://profiles.wordpress.org/santukon/) [6 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4151)
 25.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D2349%23feedback-editor-2349)
 26.   [Skip to note 20 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-357)
 27.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-357)
 28.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-357)
      Vote results for this note: 32[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-357)
 29.  **Using loop.php in child themes**
       Assuming the theme folder is `wp-content/
      themes`, that the parent theme is twentyten, and the child theme is twentytenchild,
      then the following code —
 30.      ```php
          <?php get_template_part( 'loop', 'index' ); ?>
          ```
      
 31.  will do a PHP `require()` for the first file that exists among these, in this
      priority:
 32.  wp-content/themes/twentytenchild/loop-index.php
       wp-content/themes/twentyten/
      loop-index.php wp-content/themes/twentytenchild/loop.php wp-content/themes/twentyten/
      loop.php
 33.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D357%23feedback-editor-357)
 34.   [Skip to note 21 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-359)
 35.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-359)
 36.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-359)
      Vote results for this note: 9[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-359)
 37.  **Navigation**
       Adding a navigation bar to theme using a generic `nav.php` template
      file:
 38.      ```php
          <?php get_template_part( 'nav' );           // Navigation bar (nav.php) ?>
          <?php get_template_part( 'nav', '2' );      // Navigation bar #2 (nav-2.php) ?>
          <?php get_template_part( 'nav', 'single' ); // Navigation bar to use in single pages (nav-single.php) ?>
          ```
      
 39.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D359%23feedback-editor-359)
 40.   [Skip to note 22 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4159)
 41.    [captaincainer](https://profiles.wordpress.org/captaincainer/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4159)
 42.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4159)
      Vote results for this note: 7[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4159)
 43.  A simple example of how to use the `$args` parameter in WordPress 5.5 in your
      template parts.
 44.      ```php
          <?php 
      
          $args = array( 'section_title' => 'hello world' );
      
          get_template_part( 'template-parts/file', 'name', $args ); // template-parts/file-name.php
          ```
      
 45.  In your template part.
 46.      ```php
          <h2><?php echo __( $args['section_title'] ); ?></h2>
          ```
      
 47.  Output:
 48.      ```php
          <h2>hello world</h2>
          ```
      
 49.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4159%23feedback-editor-4159)
 50.   [Skip to note 23 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4906)
 51.    [Andy Macaulay-Brook](https://profiles.wordpress.org/andymacb/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4906)
 52.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4906)
      Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4906)
 53.  Sometime since January 2019, the function has changed to return false if no template
      file is found. This isn’t noted in the code comments or changelog. The note that
      the function fails silently is no longer correct.
 54.  This now makes it easy for plugins to provide a template fallback (or allow a
      template override, depending on your perspective) like this:
 55.      ```php
          if ( false === get_template_part( $slug, $name, $args ) ) {
          	// default output
          }
          ```
      
 56.   * Return value was added in June 2020 in [changeset 48209](https://core.trac.wordpress.org/changeset/48209)
         to fix [ticket 40969](https://core.trac.wordpress.org/ticket/40969).
       * [crstauf](https://profiles.wordpress.org/crstauf/) [6 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4913)
 57.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4906%23feedback-editor-4906)
 58.   [Skip to note 24 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-1963)
 59.    [Selrond](https://profiles.wordpress.org/selrond/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-1963)
 60.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-1963)
      Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-1963)
 61.  **Get a specific file**
 62.  Although this kind of defeats the purpose of this function, it’s also possible
      to load a specific template file with it. All you have to do is use just one 
      argument:
 63.      ```php
          <?php get_template_part('template-parts/layout'); ?>
          ```
      
 64.  will include `layout.php` from _template-parts_ subdirectory placed in the root
      of your theme folder.
 65.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D1963%23feedback-editor-1963)
 66.   [Skip to note 25 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4133)
 67.    [jabbadu](https://profiles.wordpress.org/jabbadu/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4133)
 68.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4133)
      Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4133)
 69.  Since WP 5.5 the $args parameter is used to pass variables through the template.
 70.      ```php
          <?php
      
          $args = ['some data', 'to use'];
          get_template_part( 'content', '', $args ); ?>
      
          /* content.php */
          <?php print_r($args); ?>
          ```
      
 71.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4133%23feedback-editor-4133)
 72.   [Skip to note 26 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4240)
 73.    [Ahmad Karim](https://profiles.wordpress.org/ahmadkarim/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4240)
 74.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4240)
      Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4240)
 75.  You can also access the template variables in your template part file by doing
      this:
 76.      ```php
          extract( $args );
      
          echo $variable1;
          echo $variable2;
          ```
      
 77.  Your `get_template_part` will look something like this:
 78.      ```php
          $args = array(
          	'variable1' => '$variable1 Value',
          	'variable2' => '$variable2 Value',
          );
      
          get_template_part( 'template-parts/template-part-file', null, $args );
          ```
      
 79.   – Keep in mind that the third argument `$args` has been added since version 
      5.5
 80.   * WordPress PHP coding standards do not permit the use of `extract()`.
       * [crstauf](https://profiles.wordpress.org/crstauf/) [6 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4247)
 81.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4240%23feedback-editor-4240)
 82.   [Skip to note 27 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-6174)
 83.    [theaquarium](https://profiles.wordpress.org/theaquarium/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-6174)
 84.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-6174)
      Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-6174)
 85.  Please note that this function only works for _Classic_ WordPress themes. To 
      print a template part in a Block theme, use [block_template_part()](https://developer.wordpress.org/reference/functions/block_template_part/)
      instead.
 86.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D6174%23feedback-editor-6174)
 87.   [Skip to note 28 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-5092)
 88.    [pixelstorm](https://profiles.wordpress.org/dfhectik/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-5092)
 89.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-5092)
      Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-5092)
 90.  Use a boolean in the $args
 91.      ```php
          <?php get_template_part( 
              'template-parts/blocks/inc/content', 
              'section-header', 
              array( 'hasBtn' => true )
          ); ?>
          ```
      
 92.      ```php
          <?php if ( ! empty( $args['hasBtn'] ) ) { ?>
                  //show the btn on the template part
          <?php } ?>
          ```
      
 93.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D5092%23feedback-editor-5092)
 94.   [Skip to note 29 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-5437)
 95.    [Muhammad Jawad Abbasi](https://profiles.wordpress.org/jawad1234/)  [  5 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-5437)
 96.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-5437)
      Vote results for this note: 2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-5437)
 97.  **get_template_part(foldername/filename without .php extension)**
 98.      ```php
          <?php
          if(is_user_logged_in()){
          	get_template_part('template-parts/loginuser');
          }
          else{
          	get_template_part('template-parts/nonloginuser');
          }
          ?>
          ```
      
 99.  Create a folder in the theme main directory
 100. Folder name “template-parts” then add two .php files in “template-parts” folder
      loginuser.php and nonloginuser.php
 101. If user login show loginuser.php file content
 102. If the user do not login show nonloginuser.php file content
 103. **Note: Use any folder & files name above I have use random folder name and files
      name.**
 104.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D5437%23feedback-editor-5437)
 105.  [Skip to note 30 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4005)
 106.   [luboslives](https://profiles.wordpress.org/luboslives/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4005)
 107. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4005)
      Vote results for this note: -2[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4005)
 108. If your web server is using **ModSecurity**, it will likely block attempts to
      inline SVGs using a PHP method like `file_get_contents()`. You can use `get_template_part()`
      to inline SVGs.
 109.  a. Create a duplicate of your SVG, where `icon.svg` becomes `inline-icon.svg.php`
       b. Inline them in your template using `get_template_part( 'images/inline', 'icon.
          svg' );`
 110. At the time of writing, this works to get around the default OWASP rule set for
      ModSecurity. Not tested with other rule sets.
 111.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4005%23feedback-editor-4005)
 112.  [Skip to note 31 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-3229)
 113.   [Felipe Marcos](https://profiles.wordpress.org/altolord/)  [  7 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-3229)
 114. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-3229)
      Vote results for this note: -4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-3229)
 115. **Passing variables to [get_template_part()](https://developer.wordpress.org/reference/functions/get_template_part/)**
 116. It’s not possible to pass variables to a template loaded via [get_template_part()](https://developer.wordpress.org/reference/functions/get_template_part/).
      I came up with a workaround that doesn’t rely on global variables for it to work.
 117.     ```php
          /* functions.php */ 
          function get_custom_template($file = '', $arguments = []) {
            extract($arguments);
            include( locate_template( $file .'.php', false, false ) );
          }
          ```
      
 118.     ```php
          /* loop.php */ 
          while( have_posts() ): 
            the_post(); 
            get_custom_template( 'content', [
          	'is_featured' => true
            ]);
          endwhile;
          ```
      
 119. Now, when we try to use $is_featured, it will be available to **content.php**
      only.
 120.     ```php
          /* content.php */ 
          the_title(); 
          the_content(); 
          var_dump($is_featured); // true 
          ```
      
 121.  * Since WP 5.5 this is no longer needed. Use the $args parameter.
       * [jabbadu](https://profiles.wordpress.org/jabbadu/) [6 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4132)
       * WordPress PHP coding standards do not permit the use of **extract()**
       * [Yakovos Frountas](https://profiles.wordpress.org/ifrountas/) [6 years ago](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4762)
 122.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D3229%23feedback-editor-3229)
 123.  [Skip to note 32 content](https://developer.wordpress.org/reference/functions/get_template_part/?output_format=md#comment-content-4332)
 124.   [shahriyar.modami](https://profiles.wordpress.org/shahriyarmodami/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_template_part/#comment-4332)
 125. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4332)
      Vote results for this note: -4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%23comment-4332)
 126. **How to passing variables to [get_template_part()](https://developer.wordpress.org/reference/functions/get_template_part/)
      correctly: WordPress + 5.5**
 127. 1- Setup variable
 128.     ```php
          $data = array(
          	'location' 	=> 'slider',
          	'number'	=>	3
          );
          ```
      
 129. 2- Passing variable to get_template_part
 130.     ```php
          get_template_part( 'templates/slider', 'full', $data ); //templates/slider-full.php 
          ```
      
 131. 3- get data in part of template
 132.     ```php
          global $data; //dont forget use globally
          print_r($data); // output: array('location' => 'slider', 'number' => 3) 
          ```
      
 133.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F%3Freplytocom%3D4332%23feedback-editor-4332)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_template_part%2F)
before being able to contribute a note or feedback.