interactiveRob
11/4/2018 - 12:18 AM

Pass variables to get_template_part() as arguments in Wordpress

Pass variables to get_template_part() as arguments in Wordpress

function rk_get_template_part($template_slug, $args, $var_store = false) {
	
	$props = $args; 
	$template_slug = $template_slug . '.php';
	
	ob_start();

	include( locate_template($template_slug) );
	
	$template_output = ob_get_clean();
	
	if(!$var_store):
		echo $template_output;
	endif;

	return $template_output;
}