Last active
August 29, 2015 14:27
-
-
Save getdave/4506ff9992ec7809afbb to your computer and use it in GitHub Desktop.
A useful utility function for WordPress projects which loads a given template using output buffering optionally including data to be passed into template
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
/** | |
* Output Buffered Load Template Part | |
* loads a given template part using output buffering | |
* optionally including $data to be passed into template | |
*/ | |
function ob_load_template_part( $template_name, $data ) { | |
// Optionally provided an assoc array of data to pass to tempalte | |
// and it will be extracted into variables | |
if ( is_array( $data ) ) { | |
extract($data); | |
} | |
ob_start(); | |
include( locate_template( $template_name ) ); | |
$var = ob_get_contents(); | |
ob_end_clean(); | |
return $var; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment