Skip to content

Instantly share code, notes, and snippets.

@andreawetzel
Created March 16, 2017 19:04
Show Gist options
  • Save andreawetzel/0cbeeef743515ac3828cf14ea7f08548 to your computer and use it in GitHub Desktop.
Save andreawetzel/0cbeeef743515ac3828cf14ea7f08548 to your computer and use it in GitHub Desktop.
WordPress Shortcodes for Template Parts
/*
* 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