Action hook 'get_template_part'

in WP Core File wp-includes/general-template.php at line 204

View Source

get_template_part

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

Hook Information

File Location wp-includes/general-template.php View on GitHub
Hook Type Action
Line Number 204

Hook Parameters

Type Name Description
string $slug The slug name for the generic template.
string $name The name of the specialized template or an empty string if there is none.
string[] $templates Array of template files to search for, in order.
array $args Additional arguments passed to the template.

Usage Examples

Basic Usage
<?php
// Hook into get_template_part
add_action('get_template_part', 'my_custom_function', 10, 4);

function my_custom_function($slug, $name, $templates, $args) {
    // Your custom code here
}

Source Code Context

wp-includes/general-template.php:204 - How this hook is used in WordPress core
<?php
 199  	 * @param string   $name      The name of the specialized template
 200  	 *                            or an empty string if there is none.
 201  	 * @param string[] $templates Array of template files to search for, in order.
 202  	 * @param array    $args      Additional arguments passed to the template.
 203  	 */
 204  	do_action( 'get_template_part', $slug, $name, $templates, $args );
 205  
 206  	if ( ! locate_template( $templates, true, false, $args ) ) {
 207  		return false;
 208  	}
 209  }

PHP Documentation

<?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.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 4
  • File: wp-includes/general-template.php
Related Hooks

Related hooks will be displayed here in future updates.