Created
March 16, 2017 19:04
-
-
Save andreawetzel/0cbeeef743515ac3828cf14ea7f08548 to your computer and use it in GitHub Desktop.
WordPress Shortcodes for Template Parts
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
/* | |
* Add shortcode support for template parts | |
* Example: [template_part path="template-part-leadership"] | |
*/ | |
function template_part( $atts, $content = null ){ | |
$tp_atts = shortcode_atts(array( | |
'path' => null, | |
), $atts); | |
ob_start(); | |
get_template_part($tp_atts['path']); | |
$ret = ob_get_contents(); | |
ob_end_clean(); | |
return $ret; | |
} | |
add_shortcode('template_part', 'template_part'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment