I am attempting to call a template part via a shortcode. Ive read all about how to do this over and over on this site and yet after having tried a number of things still am unable to call a simple php echo time string. The file name is test-one.php .Here is what I've tried:
function test_2( $attr ) {
ob_start();
get_template_part( 'test', 'one' );
return ob_get_clean();
}
add_shortcode('test2', 'test_2');
function test_2( $attr ) {
ob_start();
get_template_part( 'test-one' );
return ob_get_clean();
}
add_shortcode('test2', 'test_2');
function test_2( $attr ) {
ob_start();
get_template_part( 'wp-content/themes/theme-name/template-parts/test-one' );
return ob_get_clean();
}
add_shortcode('test2', 'test_2');
Template part code is
<?php
echo "Current as of <br> ".date("m-d-Y h:i:sa");
Seems like it should work, no? Where am I going wrong?
wp-content
in the parameters either,'test', 'one'
was correct. When you say that it doesn't work, can you be more specifiic? The shortcode is not added? The shortcode works but there is no output? PHP fatal error? It's unclear what it's doing if it's not doing what you expected, or how you're testing this//
at the start of the comment[test2]
not[test_2]
right?