Imagine this basic shortcode in your functions.php file:
function div_shortcode( $atts ) {
return '<div class="div"></div>';
}
add_shortcode('div', 'div_shortcode');
So every [div]
in WordPress editor gives <div class="div"></div>
.
Everything looks and works fine, right?
Now here comes the trouble.
I need to use my shortcode in PHP file (not putting it via WP Text Editor).
Luckily there’s a function for that:
<?php do_shortcode('[div]'); ?>
But, wait, it shows… nothing?
<?php do_shortcode(''); ?>
Even this one doesn’t work.
Why is that happening? Any ideas?