Skip to content

Instantly share code, notes, and snippets.

@interactiveRob
Last active November 22, 2019 19:46
Show Gist options
  • Select an option

  • Save interactiveRob/5f3dc2d945b4e9c281117ba4413c2b81 to your computer and use it in GitHub Desktop.

Select an option

Save interactiveRob/5f3dc2d945b4e9c281117ba4413c2b81 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment