Skip to content

Instantly share code, notes, and snippets.

@kjbrum
Last active August 22, 2018 16:39
Show Gist options
  • Save kjbrum/7ba4f47964b16ad88ce034f3b7fba2a9 to your computer and use it in GitHub Desktop.
Save kjbrum/7ba4f47964b16ad88ce034f3b7fba2a9 to your computer and use it in GitHub Desktop.
Include a theme partial and pass data to it.
<?php
/**
* Include a theme partial and pass data to it.
*
* @param string $partial Partial file to include
* @param array $data Data to pass to the partial
* @return void
*/
function theme_include( $partial, $data = [] ) {
if ( ! strstr( $partial, '.php' ) ) {
$partial .= '.php';
}
if ( ! ( $template = locate_template( $partial ) ) ) {
throw new Exception("The partial you requested (${partial}) could not be found");
}
include( $template );
}
@hiiightower
Copy link

hey kyle,

hope you've been well.
how would this method differer from using get-template-part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment