get_template_part WordPress Action Hook

The get_template_part hook is used to include a template file from a child or parent theme. This hook is typically used in the header or footer of a theme. The get_template_part hook takes two arguments: 1. The slug of the template file to include. 2. The name of the file to be included. For example, if the slug of the template file to be included is “header” and the name of the file is “header.php”, the following code would be used: This hook is useful for including a template file from a child or parent theme. It is also useful for including a template file from a plugin.

do_action( 'get_template_part', string $slug, string $name, string[] $templates, array $args ) #

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


Parameters

$slug

(string)The slug name for the generic template.

$name

(string)The name of the specialized template.

$templates

(string[])Array of template files to search for, in order.

$args

(array)Additional arguments passed to the template.


Top ↑

Source

File: wp-includes/general-template.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
5.5.0The $args parameter was added.
5.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More