Reputation: 125
Is it possible to create a function shortcode in wordpress with get_template_part() in functions.php ?
Something like this
function custom_code( $atts ){
echo get_template_part( 'page', 'example' );
}
add_shortcode( 'custom', 'custom_code' );
thanks
Upvotes: 0
Views: 1222
Reputation: 2402
It is possible, with a small function, that render the template and get back the code.
add_shortcode( 'my_shortcode', 'fb_get_template' );
function fb_get_template() {
ob_start();
get_template_part( 'my_template' );
$content = ob_get_contents();
ob_end_clean();
return $content;
}
Upvotes: 3