Last active
December 27, 2015 13:39
-
-
Save Phize/7334629 to your computer and use it in GitHub Desktop.
WordPress: passing arguments to get_template_part() #wp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_get_template_part( $slug, $name = null, $vars = [] ) { | |
do_action( 'get_template_part_' . $slug, $slug, $name ); | |
$templates = []; | |
$name = (string) $name; | |
if ( $name !== '' ) { | |
$templates[] = $slug . '-' . $name . '.php'; | |
} | |
$templates[] = $slug . '.php'; | |
call_user_func( function ( $__templates, $__vars ) { | |
extract( $__vars, EXTR_SKIP ); | |
include( locate_template( $__templates, false, false ) ); | |
}, $templates, $vars ); | |
} | |
// my_get_template_part( 'slug', 'name', [ 'var' => $var ] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment