Skip to content

Instantly share code, notes, and snippets.

@stephenyeargin
Created August 26, 2011 03:26
Show Gist options
  • Save stephenyeargin/1172609 to your computer and use it in GitHub Desktop.
Save stephenyeargin/1172609 to your computer and use it in GitHub Desktop.
Easy way to embed static content within WordPress posts and pages.
function get_partial($args) {
// If empty, return false
if (!isset($args['name']))
return false;
// If file exists, include it
$filename = sprintf(TEMPLATEPATH . '/assets/partials/%s.php', $args['name']);
if (file_exists($filename)):
ob_start();
include( $filename );
$output = ob_get_contents();
ob_end_clean();
endif;
return $output;
}
add_shortcode( 'partial', 'get_partial' );
/*
Usage: [partial name="myfile"]
Loads: /path-to-theme-folder/assets/partials/myfile.php inline
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment