Created
August 26, 2011 03:26
-
-
Save stephenyeargin/1172609 to your computer and use it in GitHub Desktop.
Easy way to embed static content within WordPress posts and pages.
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
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