Is it possible to develop a function shortcode 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
Is it possible to develop a function shortcode 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
get_template_part
is echoing the HTML code. and the shortcode function must return the content.
then you can try that :
function custom_code($attr, $content, $tag)
{
ob_start();
get_template_part( 'page', 'example' );
$content = ob_get_clean();
return $content;
}
add_shortcode( 'custom', 'custom_code' );