I use a shortcode on my page like
[abc a="b"]test[/abc]
In my functions.php
add_shortcode('abc', function($atts, $content) {
return $atts['a']." : ".$content;
});
And in my template somewhere
<p><?php echo do_shortcode('[abc]') ?></p>
$atts, $content are always empty.
Everything works fine in the Default template but not in mine.
I really appreciate if anyone can show me how to get it work in my custom template. Thanks
You should add these line of code in your custom page template , it will automatically apply filters on content like wpautop
and other shortcodes
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post() ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; else : ?>
<?php endif; ?>
I used this:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
instead of this:
<?php echo do_shortcode('[abc]') ?>
and it worked